Jump to content

Double table insert not working


Shamrox

Recommended Posts

I have a simple form that submits into two tables. the first table would generate an id that would then be submitted into the second table along with some other info. It seemed to be working, but i have several users that can never seem to get anything to save to the main table. I look in the database and the main table will not have an entry, but the secondary table will have an entry, but the ID field will be blank. Here is the sql, could you please tell me what might be wrong??

[code]
if (isset($_POST['name'])) {
$name = $_POST['name'];
  $ok1 = @mysql_query("INSERT INTO spec_supplier SET
  name='$name',
  ctype='$ctype',
  caption='$caption',
  online='$online',
  sidebar_title='$sidebar_title',
  sidebar_content='$sidebar_content' ");
$ok2 =  @mysql_query("INSERT INTO spec_categories SET sid=(last_insert_id()), catname='$name' ");
  if ($ok1 and $ok2) {
echo '
<p>Supplier added successfully.';
  } else {
  echo '<p>Error adding submitted supplier: ' .
  mysql_error() . '</p>';
}
}
[/code]
Link to comment
https://forums.phpfreaks.com/topic/31601-double-table-insert-not-working/
Share on other sites

[quote author=artacus link=topic=119646.msg490561#msg490561 date=1166859037]
Actually LAST_INSERT_ID() is a mysql function,
mysql_insert_id() is the PHP function.
[/quote]
Sorry, my bad... that's what I thought it said.

[quote author=Shamrox link=topic=119646.msg490929#msg490929 date=1166928882]
I got it working after altering my code a bunch and then returning to almost what I started with, except for the fact that I used all caps for LAST_INSERT_ID(). Does the case matter for this function? Only thing I can think of that cause it not to work.
[/quote]

I believe there's a server config option for this, but I have no idea if the default is sensitive or not.

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.