Php Programming Code Examples
Php > Complete Programs Code Examples
This program will take data from a user via a web based form, validate it, show it
This program will take data from a user via a web based form, validate it, show it
<html>
<body bgcolor="AAAAAA" text="000000"></body>
<title>Web and Email registration</title>
<center><table border=1 bgcolor="#086b5a" bordercolor="086b5a">
<tr><td><center><img src="reg.gif"><IMG SRC="logot.gif"></center></TD>
</tr>
</table></center>
<?
if (!$namef && !$insertval && !$submit) {
echo "<form action=\"/reg.php3\" method=\"post\">";
echo "<center>";
echo "<table align=\"center\" border=1 bordercolordark=\"#777777\" width=\"60%
\" bordercolorlight=\"#dddddd\" bgcolor=\"BBBBBB\">";
echo "<tr><td colspan=2 bgcolor=\"#000000\"><center><font color=\"#aaddaa\"> Jap
an Communication Inc.</font></center></td></td>" ;
echo "<tr><td>Your first name<br>";
echo "<td><input type=\"text\" name=\"namef\" maxlength=40
length=40><br></tr></td>";
echo "<tr><td>Your last name<br></td>";echo "<td><input type=\"text\" name=
\"namel\" maxlength=40 length=40><br></tr></td>";
echo "<tr><td>Your company name</td>";
echo "<td><input type=\"text\" name=\"coname\" maxlength=120 length=40><br></tr>
</td>";
echo "<tr><td>Your email address<br>";
echo "<A4><A4><A1><CB></td>";
echo "<td><input type=\"text\" name=\"email\" maxlength=60 length=40><br></tr></
td>";
echo "<tr><td>Your cell phone's number (numbers only please)";
echo "";
echo "<td><input type=\"text\" name=\"mobileset\" maxlength=15
length=40></tr></td>";
echo "<tr><td>A personal password<br>";
echo "</td>";
echo "<td><input type=\"password\" name=\"pass\" maxlength=40
length=40></tr></td>";
echo "<tr><td>A personal password (again)";
echo "</td>";
echo "<td><input type=\"password\" name=\"pass2\" maxlength=40 length=40></tr></
td>";
echo "<tr><td>Finish and submit data<br><BD><AA><CE><BB></td>";
echo "<td><center><input type=\"submit\" name=\"submit\" value=\"<C5><D0><CF>
<BF>\"></center></tr></td>";
echo "<tr><td colspan=2 bgcolor=\"#000000\"><center><font color=\"#aaddaa\">
Copyright 1998</font></center></td></td>" ;
echo "</table></center></form>";
} ?>
<?
if($pass != $pass2){
echo "<br><br><hr>You mispelled your password<hr><br><br>";
echo "Please <a href=\"/reg.php3\">go back</a> to correct this";
die;
}
if(!$insertval && $namef && $email && $namel && $pass && $coname) {
echo "<center><table border=1 bgcolor=\"#CCCCCC\"><tr><td colspan=6>" ;
echo "<br><center>You entered these values </center></td></tr>";
echo "<tr><td>First Name</td><td>Last Name</td><td>Company
Name</td><td>Email Address</td><td>";
echo "Phone Number</td><td>Password</td></tr>";
echo "<tr><td>$namef</td><td>$namel</td><td>$coname</td><td>
$email</td><td>mobileset</td><td>NOT SHOWN</td></tr>";
echo "</td></tr>";
echo "<form action=\"reg.php3\" method=\"post\">";
echo "<td colspan=3>Is all this data Correct?</td><td colspan=3>";
echo "<center><input type=\"submit\" value=\"Yes\" name=\"insertval\">";
echo "<input type=\"submit\" value=\"No\" name=\"insertval\">";
echo "<input type=\"hidden\" name=\"namef\" value=\"$namef\">";
echo "<input type=\"hidden\" name=\"namel\" value=\"$namel\">";
echo "<input type=\"hidden\" name=\"coname\" value=\"$coname\">";
echo "<input type=\"hidden\" name=\"email\" value=\"$email\">";
echo "<input type=\"hidden\" name=\"mobileset\" value=\"$mobileset\">";
echo "<input type=\"hidden\" name=\"pass\" value=\"$pass\">";
echo "<input type=\"hidden\" name=\"pass2\" value=\"$pass2\">";
echo "</form></table></center></center>";
} elseif($insertval == "No") {
echo "<font size=+2><center><br><br><hr>If you made a mistake, ";
echo "Click <a href=\"/reg.php3\">here</a> to start
over<hr></font></center><br><br>";
}
if((!$namef || !$email || !$namel || !$pass || !$coname || $insertval) &&
$submit) {
echo "<font size=+1><center><br><br><hr>";
echo "You <font color=\"#FF0000\"><b>must</b></font> enter data in the
following fields:<br>";
echo "First name, Last Name, email, Company Name, and password";
echo "Click <a href=\"/reg.php3\">here</a> to start over";
echo "</font></center><hr><br><br>";
}
if($insertval == "Yes"){
mysql_connect("localhost","root","mypassword")
or die("Unable to connect to MySQL server");
mysql_select_db("register") or die("Unable to select database");
$insert = mysql_query("insert into users VALUES(
'$namef','$namel','$coname','$email','$mobileset',password
('$pass'),NULL)");
echo "<br><br><b><font size=+4><font color=\"66FF66\"><center>Your data has
been successfully entered.";
echo "</b></center></font></font>";
}
?>
<center><table border=1 width="90%"
bgcolor="#086b5a"><tr><td><FORM><center><font color="FFFFFF">
<INPUT bgcolor="#AAFFAA"type="button" value="Main Menu"
OnClick="location='./index.html'"></font></form></td>
</center>
<TD><font color="DD5555"><center><h1>Widget
Inc.</h1>company name here</center></td></tr></table></center>
</html>