|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
Mysql & other databases - Can't Insert a variable into the database
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 Nickel |
|
#2
|
||||
|
||||
|
I'm not sure why you have:
PHP Code:
BEFORE PHP Code:
Try moving it after you execute $insertSQL.
__________________
/** * @author EHSANUL HAQUE * @profession Web Application Developer * @location North York, ON, Canada */ |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Mysql & other databases - Can't Insert a variable into the database |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|