Seo Master present to you: form.php
<pre> <html> <head> <title>Personal INFO</title> </head> <body> <?php if($_REQUEST['err']) {?> <br /> <div style="border:1px solid red;text-align:center;width:600px;margin:auto;color:red;"> <?php echo $err=$_REQUEST['err']; ?> </div> <?php } ?> <?php if($_REQUEST['succes']) {?> <br /> <div style="border:1px solid green; background:#00FFCC;text-align:center;width:800px;margin:auto;color:green;"> <?php echo $succes=$_REQUEST['succes']; ?> </div> <?php } ?> <br /> <form method="post" action="form-action.php"> <table align="center" bgcolor="#CCCCCC";> <tr> <td>First Name:</td> <td><input type="text" size="12" maxlength="12" name="Fname"> <td>Last Name:</td> <td><input type="text" size="12" maxlength="36" name="Lname"> </td> </tr> <tr> <td><input type="hidden" name="id"></td> </tr> <tr> <td>Gender:</td> <td><input type="radio" value="Male" name="gender">Male</td> <td><input type="radio" value="Female" name="gender">Female</td> </tr> <tr> <td>Please choose type of residence</td> <td><input type="checkbox" value="Burger" name="food[]">Burger</td> <td><input type="checkbox" value="Pizza" name="food[]">Pizza</td> <td><input type="checkbox" value="Chicken" name="food[]">Chicken</td> </tr> <tr> <td>Your comments:</td> <td><textarea rows="5" cols="20" name="quote"></textarea></td> </tr> <tr> <td>Select a Level of Education:</td> <td><select name="education"> <option value="Jr.High">Jr.High</option> <option value="HighSchool">HighSchool</option> <option value="College">College</option></select></td> </tr> <tr> <td>Select your favorite time of day:</td> <td> <select name="TofD" size="3"> <option value="Morning">Morning</option> <option value="Day">Day</option> <option value="Night">Night</option></select> </td> <tr> <tr> <td><input style="margin-left:150px;" type="submit" value="login" name="submit"></td></tr> </tr> </table> </form> </pre> form-action.php <pre> <?php mysql_connect("localhost","root","") or die (mysql_error()); mysql_select_db("formexample") or die (mysql_error()); if(isset($_REQUEST['submit'])) { $Fname = $_POST["Fname"]; $Lname = $_POST["Lname"]; $gender = $_POST["gender"]; $food = $_POST["food"]; $quote = $_POST["quote"]; $education = $_POST["education"]; $TofD = $_POST["TofD"]; if(empty($Fname)) { $error="First Name cannot be empty"; } else if (empty($Lname)) { $error="Last Name cannot be empty"; } else if (empty($gender)) { $error="Gender cannot be empty"; } else if (empty($food)) { $error="Food cannot be empty"; } else if (empty($quote)) { $error="Quote cannot be empty"; } else if (empty($education)) { $error="Education cannot be empty"; } else if (empty($TofD)) { $error="Favorite time cannot be empty"; } if($error==NULL) { $data=""; $data=implode(",",$food); $query="insert into form values('','$Fname','$Lname','$gender','$data','$quote','$education','$TofD')"; $result=mysql_query($query); if($result) { $succes = "Succesfuly added your information"; } ?> <body onLoad="document.myform.submit(); "> <form name="myform" method="post" action="form.php?&succes=<?php echo $succes; ?>"></form> </body> <?php } else { ?> <body onLoad="document.myform.submit(); "> <form name="myform" method="post" action="form.php?&err=<?php echo $error; ?>"></form> </body> <?php } } ?> </pre>2013, By: Seo Master |
Labels: