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