valoukh Posted March 8, 2008 Share Posted March 8, 2008 hey all. I'm trying to insert data into two tables at once and I'm not really sure what I'm doing wrong. When I submit the data, it only gets inserted into the News table; the Gigs one is ignored. Thanks in advance for any help! <? $sql="INSERT INTO Gigs (gigdate, venue, venueaddress, info, date, gigtime) VALUES ('$_POST[gigdate]','$_POST[venue]','$_POST[venueaddress]','$_POST[info]', '$_POST[date]','$_POST[gigtime]')"; $sql="INSERT INTO News (title, content, date) VALUES ('New gig added!','Denby Grace will be at $_POST[venue] on $_POST[gigdate]. See the Gigs page for more info!','$_POST[date]')"; if (!mysql_query($sql,$dbh)) { die('Error: ' . mysql_error()); } echo "Gig added, thanks!"; mysql_close($dbh) ?> Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 8, 2008 Share Posted March 8, 2008 you never run mysql_query() on the first $sql before you set it to another value. for 2 different SQL statements, you'll need to call mysql_query() twice, once for each SQL statement. Quote Link to comment Share on other sites More sharing options...
valoukh Posted March 8, 2008 Author Share Posted March 8, 2008 Thanks for your speedy response! I tried it like this but I'm not sure I understand the difference (this didn't work either): mysql_query("INSERT INTO Gigs (gigdate, venue, venueaddress, info, date, gigtime) VALUES ('$_POST[gigdate]','$_POST[venue]','$_POST[venueaddress]','$_POST[info]', '$_POST[date]','$_POST[gigtime]'"); mysql_query("INSERT INTO News (title, content, date) VALUES ('New gig added!','Denby Grace will be at $_POST[venue] on $_POST[gigdate]. See the Gigs page for more info!','$_POST[date]'"); Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 8, 2008 Share Posted March 8, 2008 $sql="INSERT INTO Gigs (gigdate, venue, venueaddress, info, date, gigtime) VALUES ('$_POST[gigdate]','$_POST[venue]','$_POST[venueaddress]','$_POST[info]', '$_POST[date]','$_POST[gigtime]')"; if (!mysql_query($sql,$dbh)) { die('Error: ' . mysql_error()); } $sql="INSERT INTO News (title, content, date) VALUES ('New gig added!','Denby Grace will be at $_POST[venue] on $_POST[gigdate]. See the Gigs page for more info!','$_POST[date]')"; if (!mysql_query($sql,$dbh)) { die('Error: ' . mysql_error()); } echo "Gig added, thanks!"; mysql_close($dbh) Quote Link to comment Share on other sites More sharing options...
valoukh Posted March 8, 2008 Author Share Posted March 8, 2008 now I understand! it works like a charm. Thanks so much for your help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.