I'll use an example from another application, admin_page.php to add names, and id and tips to a db with a form.
Some syntax always stay the same - you just learn and remember it.
//connection to db always required
mysql_connect();
$add=$_POST['Add']; like you've learned
// from the submit button in the form - to see if form was posted
if(isset($Add)) // standard syntax to see if a variable exists. You can get away without using isset, as in if($add){ }, but this is safer.
//get variables posted with form
$new_name=$_POST['new_name'];
$new_tip=$_POST['new_tip'];
//insert statement, insert variables in exact order as the fields exist in the table, Say they are,and their order is name, id and tip
mysql("db_name", "INSERT INTO table_name VALUES (
'$new_name',
'', //this is an auto increment field - send an empty '' and it will increment by itself
'$new_tip' //note the last does not have a comma - watchout!
)"
;
// I want to get the id just generated - do a simple select after the insert (i'm not using it in this example, so I put it here as an example)
mysql_select_db("db_name"
or die( "Unable to select database"
;
$result = mysql_query( "SELECT * from table_name WHERE name='$new_name'"
; // WHERE clause to point the query to the exact row whos id I want - I have the $new_name from here above, so I use that to point the query. Of course I can use WHERE name='$new_name AND tip='$tip' as well just in case names can be the same then tip will narrow it down even further.
while($row = mysql_fetch_row($result)) // $result is what I used here above. $row can be any thing - you create the $row variable using the mysql_fect_row function which is built into PHP.
{
$id = $row[1]; using this syntax (there are other ways to do selects) [0] would be the first field, [1] the second field and so on. The order in which the fields exist in the table.
}
// here I echo my results in a html table
echo "<table border=0 align=center><tr><td><b><u>Admin Interface to add a Name and Tip.</u></b><br><br>
<strong>Tip added!</strong><br><br>
<a href='admin_page.php'>Add another</a><BR>or<BR> // this will reload this page, but since Add does not exist in this URL I'm sending, the form below will show
<a href='index.php'>Go to website</a><br><br>";
echo "</td><td></tr><table>";
//should I wanted to use the $id, I can use it however I want to use it. E.g. <a href='page.php?id=$id'>Go do this now</a><br><br>";
}
else //show the form
{
echo "<div align=center><b><u>Admin Interface to add name and tip.</u></b><br><br>
<a href='index.php'>Go to website</a><br><br>
<form method='POST' action=''>"; // leaving action empty - it will go to this same page
echo " <br><b>Add New Name and Tip</b><br><br></div>";
echo "
<table border='0' cellpadding='3' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' align=center>
<tr>
<td><b>Name</b></td>
<td><input type='text' name='new_name'></td>
</tr><tr>
<td><b>Tip</b></td>
<td><textarea name='new_tip' rows=5 cols=50></textarea></td>
</tr><tr>
<td><b>Action</b></td><td>
<input type='submit' value='Add' name='Add'> //
<input type='reset' value='Reset'></form>
</td>
</tr>
</table><hr size='1'>";
}
?>