I am having trouble inserting information into more than one mysql table. In the code below, you'll see that I am trying to insert "name" into table1. When that insert is successful, I would like to see the form that inserts "color" into table2. From the code below, this all works fine, except an empty row is inserted in both tables every time. I know the code is iffy, but I think I am close. Any suggestions?? Thanks!
<form action="<? echo $PHP_SELF; ?> " method="POST">
Name:
<input size="50" maxlength="25" type="text" name="name">
<input type="Submit" name="submit" value="Add Information">
<?
}
else
{
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
mysql_select_db($db) or die ("Unable to select database!");
$query =[COLOR=blue] "INSERT INTO table1 (name) VALUES([B]'[/COLOR]$name'[COLOR=blue][/B])"[/COLOR];
$result = mysql_query($query) or die ([COLOR=blue]"Error in query:[/COLOR] [B]$query[/B]. " . mysql_error());
echo " <form action=[B]"$PHP_SELF[/B]\" method=\"POST\">";
$query = "INSERT INTO table2 (color) VALUES ('$color')";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
echo " Color:";
echo " <input size=50 maxlength=250 type=text name=color>";
echo " <input type=Submit name=submit value=Add Information>";
echo " </form> ";
mysql_close($connection);
?>
</form>