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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.