|
[back] Populating the Table: Using a PHP script with an HTML form There is an easier method of getting information into your table. You can create a simple HTML page and pass the information through forms. First, you need to set up an HTML input page: <html> <form action="insert2.php" method="post"> First Name: <input type="text" name="first"
SIZE="30"><p> Graduation Year: Student Number: <input type="text" name="student_no"
SIZE="6"><p> HTML Explained: This is a pretty straight forward form. Note that the Action is being sent to our input2.php page. (which we will create in a minute) Also note that I set up the Graduation Year as a pull down menu. Remember that when we set up our table we set this field as an "INT". If the user would type in "freshman", the entire entry would be dropped. Another option would be to have a text field and then use a conditional to check that the value was an integer. Creating the PHP page: <?php $first=$_POST['first']; mysql_connect(localhost,$user,$password); $query = "INSERT INTO students VALUES ('','$first','$last','$grad_year','$student_no')"; mysql_query($query); ?> PHP Explained: Create a new HTML page called input.htm and a new php page and named "insert2.php". Insert the next couple of students from names and info you make up. |