Error messge in php

Step 1: registration.php
lt;?PHP
if($_REQUEST['err']) {?gt;
lt;br /gt;
lt;div style="border:1px solid red;text-align:center;width:400px;margin:auto;color:red;"gt;
lt;?php echo $error=$_REQUEST['err']; ?gt;
lt;/divgt;

lt;?php } ?gt;

lt;?PHP
if($_REQUEST['succes']) {?gt;
lt;br /gt;
lt;div style="border:1px solid red;text-align:center;width:400px;margin:auto;color:red;"gt;
lt;?php echo $succes=$_REQUEST['succes']; ?gt;
lt;/divgt;

lt;?php } ?gt;

lt;/brgt;

lt;htmlgt;
lt;headgt;
lt;/headgt;
lt;bodygt;
lt;form action="registration_action.php" method="post"gt;
lt;centergt;
lt;divgt;
lt;font size=5gt;USER REGISTRATIONlt;/fontgt;
lt;brgt;
lt;font size=1gt;lt;supgt;*lt;/supgt; Required Fieldslt;/fontgt;
lt;brgt;
lt;input type="hidden" name="id"gt;
lt;brgt;
lt;bgt;First Namelt;supgt;*lt;/supgt;lt;/bgt;

lt;input type="text" name="firstName" size=15 maxlength=20gt;
lt;brgt;
lt;brgt;
lt;bgt;Last Namelt;supgt;*lt;/supgt;lt;/bgt;

lt;input type="text" name="lastName" size=15 maxlength=20gt;

lt;brgt;
lt;brgt;
lt;bgt;User Namelt;supgt;*lt;/supgt;lt;/bgt;

lt;input type="text" name="userName" size=15 maxlength=20gt;
lt;brgt;
lt;brgt;
lt;bgt;Passwordlt;supgt;*lt;/supgt;lt;/bgt;

lt;input type="password" name="password1" size=15 maxlength=20 style="margin-left:10px;"gt;
lt;brgt;
lt;brgt;
lt;bgt;Confirm Passwordlt;supgt;*lt;/supgt;lt;/bgt;
lt;input type="password" name="password2" size=15 maxlength=20gt;
lt;brgt;
lt;brgt;


lt;bgt;What music are you interested in?lt;/bgt;
lt;brgt;
lt;input type="checkbox" name="faveMusic[]"
value="Rock"gt;Rock
lt;input type="checkbox" name="faveMusic[]" value="Pop"gt;Pop
lt;input type="checkbox" name="faveMusic[]" value="Bluegrass"gt;Bluegrasslt;brgt;
lt;input type="checkbox" name="faveMusic[]" value="Blues"gt;Blues
lt;input type="checkbox" name="faveMusic[]" value="Jazz"gt;Jazz
lt;input type="checkbox" name="faveMusic[]" value="Country"gt;Countrylt;brgt;



lt;bgt;What u are?lt;/bgt;
lt;brgt;
lt;input type="radio" name="male_female" value="Male" checkedgt;Male

lt;input type="radio" name="male_female" value="Female" gt; Female
lt;brgt;
lt;brgt;
lt;input type="submit" name="submit" value="Submit"gt;
lt;input type="reset" value="Reset"gt;
lt;/divgt;

lt;/centergt;
lt;/formgt;

lt;/bodygt;
lt;/htmlgt;


Step 2. registration.php


lt;?php
if(isset($_REQUEST['submit']))
{
mysql_connect("localhost","root","") or die (mysql_error());
mysql_select_db("registration") or die (mysql_error());


// Variable Section

$firstName=$_REQUEST['firstName'];
$lastName=$_REQUEST['lastName'];
$userName=$_REQUEST['userName'];
$password1=$_REQUEST['password1'];
$password2=md5($_REQUEST['password2']);
$faveMusic=$_REQUEST['faveMusic'];
$male_female=$_REQUEST['male_female'];

//Error Message
if(empty($firstName))
{
echo $error="Firstname Cannot be Empty";
}

else if(empty($lastName))
{
echo $error="Lastname Cannot Be Empty";
}

else if(empty($password1))
{
echo $error="Password Cannot Be Empty";
}
else if(empty($password2))
{
echo $error="Confirm Password Cannot Be Empty";
}

else if(empty($faveMusic))
{
echo $error="Music Cannot Be Empty";
}

else if(empty($male_female))
{
echo $error="male /female Cannot Be Empty";
}





if ($error==NULL)
{
//transfer to Mutliple Data in check box
$data="";
$data=implode("",$faveMusic);
$sql="INSERT into tbl_registration

VALUES

('','$firstName','$lastName','$email','$userName','$password1','$password2','$data','$male_female)";
$result=mysql_query($sql);
if($result)
{
$succes="Successfully inserted";
header("location:login.php");
}

?gt;


lt;body onLoad="document.form.submit();"gt;
lt;form name="form" method="post" action="registration.php?&succes=lt;?php echo $succes;?gt;"gt;
lt;/formgt;
lt;/bodygt;


lt;?php
}else{
?gt;
lt;body onLoad="document.form.submit();"gt;
lt;form name="form" method="post" action="registration.php?&err=lt;?php echo $error;?gt;"gt;
lt;/formgt;
lt;/bodygt;
lt;?php
}
}
?gt;

0 Response to "Error messge in php"

Post a Comment

powered by Blogger | WordPress by Newwpthemes | Converted by BloggerTheme