|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Can't insert field into table after mysql_insert_id
Hi everybody,
Usually, I can figure things out from lots of searching, but not this time. I'm new at PHP and MySQL. Trying to do something fairly simple - grab a field that was autoincremented in one table, and insert into another. A common thing, I'm sure. Database inserting works until I try to insert the autoincrement field into the other table. No matter what, I can't get anything into that spot. Here's the code: if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO companies (company_name) VALUES (%s)", GetSQLValueString($_POST['company'], "text")); $id = mysql_insert_id(); echo $id; mysql_query("INSERT INTO customers (company_id) VALUES ('$id')"); mysql_select_db($database_presort, $presort); $Result1 = mysql_query($insertSQL, $presort) or die(mysql_error()); } I know that the mysql_insert_id is working because when I echo the $id variable, I get the right number. But the insert won't work. I would be ever so grateful for any help at all, ideas, etc. I know everybody's got their problems, so thanks in advance for any help for this newbie. Karey |
|
#2
|
|||
|
|||
|
Quote:
Try instead of it: $q = sprintf("INSERT INTO customers(company_id) VALUES(%d)", $id); mysql_query($q) or die(mysql_error()); |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > Can't insert field into table after mysql_insert_id |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|