if ($submit)
{
$query = "INSERT INTO home (address1, address2)
values ( '$address1', '$address2')";
print "Your listing has been added!";
}
print "<form name="add" action="add.php" method=post>";
print "Address1: <input type="text" name="address1">";
print "Address2: <input type="text" name="address2">";
print "<input type=submit name=submit value=Submit Listing></form>";
Here is my question, i have 2 tables, one called home, one called office, I want address1 to be inserted into home table, and I want address2 to be inserted into office table, anybody knows what i have to do with mySQL query? Or what is the better way to do this?
if ($submit)
{
@$db_conn = mysql_connect($host, $user, $pass) or die(mysql_error());
@mysql_select_db($db) or die(mysql_error());
$query1 = "INSERT INTO home (address1)
values ( '$address1')";
$query2 = "INSERT INTO office (address2)
values ('$address2')";
@mysql_query($query1) or die(mysql_error());
@mysql_query($query2) or die(mysql_error());
@mysql_close() or die(mysql_error());
print 'Your listing has been added!';
}
print '<form name="add" action="add.php" method=post>';
print 'Address1: <input type="text" name="address1" />';
print 'Address2: <input type="text" name="address2" />';
print '<input type="submit" name="submit" value="Submit Listing" /></form>';
Don't forget to connect and actually run the query . Also using single quotes around the print strings means you don't have to escape all the double quotes in the HTML.