In the first post, cited above, I showed how in the processing program defined in the action parameter of the form you should use $_POST[...] for getting access to the values in the form.
So you just need to declare some PHP variables and get those values into them, like:
$name = $_POST["name"];
....
If in the form you had a field name as "name".
After that you use the part from from the Demo File (only one INSERT statement) but instead of the hard coded values - use the variables from shown above with values from the form
...
mysql_query("INSERT INTO people (FirstName, LastName, Age)
VALUES ('$name', and other similar variables here)");
The reading program is actually in the same Demo File after the comment:
//Read the result
$result = mysql_query("select * from people");
if (!$result)
{
die('Could not read: ' . mysql_error());
}
echo "got records!";
echo "Passed!";
while($row = mysql_fetch_array($result))
{
echo $row['FirstName'] . " " . $row['LastName'];
}
mysql_close($con);
echo "Finished";
?>
You just need to use this code in a separate program where you first select the database (all my code from the Demo File up to the couple of INSERT statements) and then skipping INSERT statements in the Demo File use the code after "//Read the result " comment.
And that's it!
Make this lab work (who couldn't ) to get the grade that you deserve, resubmit the forum and the assignment A11.2 and email me about the completion. Your grade might be somewhat increased but, what is more important, you will be able to get a better course grade. Otherwise, even if all other labs work - it cannot be more than a B, since this lab uses cumulative knowledge from the previous weeks on PHP and MySQL.
Alternatively, you can use the code from w3schools where the same form file was calling itself for processing (I described it in my another post), but still will need to use the variables taking info from $_POST[...] method. But I think what I showed above is simpler (but for real life code remember that for simplicity in the shown code we didn't use protection against PHP injection as described on w3schools site).
No comments:
Post a Comment