Shamrox Posted December 22, 2006 Share Posted December 22, 2006 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] Quote Link to comment Share on other sites More sharing options...
fenway Posted December 22, 2006 Share Posted December 22, 2006 If you want to use last_insert_id() -- a PHP function -- you had better break it out of that stringe. Quote Link to comment Share on other sites More sharing options...
artacus Posted December 23, 2006 Share Posted December 23, 2006 Actually LAST_INSERT_ID() is a mysql function, mysql_insert_id() is the PHP function.I'd suggest not suppressing the error msg from mysql_query because if your first query fails you shouldn't go on to the second one. Quote Link to comment Share on other sites More sharing options...
Shamrox Posted December 24, 2006 Author Share Posted December 24, 2006 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 Link to comment Share on other sites More sharing options...
fenway Posted December 26, 2006 Share Posted December 26, 2006 [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. 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.