Here is my HTML Code:
<html>
<head>
<title>Record Insertion>
</head>
<body>
<form action="insert.php" method="POST">
<p>The First Hale Database<br>
Age <input type="text" name="Age" size="2"><br>
First Name <input type="text" name="First_Name" size="30"><br>
Last Name <input type="text" name="Last_Name" size="30"> <br>
<p><input type="submit" name="submit" value="Add Me"></p>
</form>
</body>
</html>
Here is my PHP code:
<?php
$mysqli = new mysqli("localhost", "root", "pass", "test");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
} else {
$sql = "INSERT INTO testTable (Age)
VALUES ('".$_POST["Age"]."')";
$res = mysqli_query($mysqli, $sql);
-----------------missing the rest of the form INSERT INTO here only inserting Age------------------------
if ($res === TRUE) {
echo "record has been inserted";
} else {
printf("could not insert record: %s\n", mysqli_error($mysqli));
}
mysqli_close($mysqli);
}
?>
Using text books. I am training myself with mysql and php. I have inserted my first value into my first database/database table using the above form and script. However this is just basic and as you can see I have additional form fields in my html that i would like to insert into my test database/testtable. the database is ready to accept these posts, however what is an "experienced" way the PHP code should read for the rest of my HTML form fields?