views:

375

answers:

4
$sql = "INSERT INTO images (path, useremail, approved, flagged,caption,date) VALUES ('$target','$email',0,0, '$caption','$b')";
$sql1 = "INSERT INTO users (name, email, phone) VALUES ('$peoplename','$email','$phone')"
$conn->execute($sql, $sql1);

Above is the code Ι am using to try and write to 2 tables. Before Ι introduced connection through the COM object Ι could do this not a problem but now Ι cannot do it for some reason. Any help would be appreciated.

A: 

You have a missing semicolon on the second line.

Sani Huttunen
alas, not the problemCheers though
+5  A: 

I thought that the second parameter was for passing parameters to be bound to the query.

If the server lets you execute two sql statements in one go maybe this would work. (added a terminating semi-colon at the end of each query and concatenated both queries together as one string.)

$sql = "INSERT INTO images (path, useremail, approved, flagged,caption,date) VALUES ('$target','$email',0,0, '$caption','$b');";
$sql1 = "INSERT INTO users (name, email, phone) VALUES ('$peoplename','$email','$phone');";
$conn->execute($sql . $sql1);

otherwise the obvious

   $conn->execute($sql); 
   $conn->execute($sql1);
Tom Haigh
If both INSERTs must succeed (or fail) together, enclose them in a transaction using "BEGIN TRANS;" AND "COMMIT;" OR "ROLLBACK;" statements. Alternatively, if $conn is a ADODB connection object, you can use it's native methods ("BeginTrans()"," CommitTrans()", "RollbackTrans()").
Tomalak
A: 

Why not put it as one SQL statement?

$sql = "INSERT INTO images (path, useremail, approved, flagged,caption,date) VALUES ('$target','$email',0,0, '$caption','$b'); INSERT INTO users (name, email, phone) VALUES ('$peoplename','$email','$phone')";
$conn->execute($sql);
Oli
A: 

Drew, I'm not a PHP guru, but one thing I see missing in the other answers is transactional integrity. Even stacking the two INSERTs in the same string seperated with a semicolon does ensure atomicity of the action (if that is important to you :-)

Hope this helps

James Green
Alas no. Cheers though