Jump to content

Insert into multiple mysql tables, only 1 works


valoukh

Recommended Posts

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)
?>

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]'");

$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)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.