0

i am working on a project where i have to insert records in two diffetent table at a time so i am using transactions but it donot insert the record when i execute the query from .php file but if i echo query and copy its output from browser and paste it inside phpmyadmin SQL window it works fine

$insert_device_order = "START TRANSACTION;
                                INSERT INTO request 
                                VALUES ('', '', '$spoc_id', '$spoc_username', '', '', 'Device', 'Submitted','$spoc_id' );
                                INSERT INTO devices 
                                VALUES ( '', LAST_INSERT_ID( ) , '$device_msisdn', '$device_payment','$device_offer', '$device_device' );  
                            COMMIT;";

    $result = mysql_query($insert_device_order);

    if($result){header("Location: addDevices2.php");}else{ echo "cannot insert";}

i am unable to find the issue as i checked my config file is also included at the top.

i use this method to to over come this issue but it also do not worked

mysql_query("START TRANSACTION");
    mysql_query("INSERT INTO request VALUES ('', '', '$spoc_id', '$spoc_username', '', '', 'Device', 'Submitted','$spoc_id' )");
    mysql_query("INSERT INTO devices VALUES ( '', LAST_INSERT_ID( ) , '$device_msisdn', '$device_payment','$device_offer', '$device_device' )");
    mysql_query('COMMIT');
kwk.stack
  • 553
  • 1
  • 9
  • 21

1 Answers1

1

If you read the fine manual:

Warning

This extension is deprecated as of PHP 5.5.0, and will be removed in the future.

...

mysql_query() sends a unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier.

Parameters

query

An SQL query

The query string should not end with a semicolon.

Emphasis mine. You're sending four queries (and ending them all with a semicolon, to boot).

Call mysql_query multiple times. Or better yet, stop using mysql_*.

Community
  • 1
  • 1
ta.speot.is
  • 26,914
  • 8
  • 68
  • 96
  • i am not getting you can you edit my query and paste it in your answer so that i could compare with mine to find and understand my error – kwk.stack Oct 02 '13 at 12:04
  • 1
    One query is all that will be processed: `START TRANSACTION`. – ta.speot.is Oct 02 '13 at 12:05
  • can any one one edit my query for error so that i know in future about this issue – kwk.stack Oct 02 '13 at 12:11
  • i edit my question for mulipltle mysql_query have kind look plz – kwk.stack Oct 02 '13 at 12:30
  • There is an example [here](http://stackoverflow.com/a/2708424/242520) but pay attention to the comments as well. Make sure you do appropriate error checking and while debugging, log errors to the screen. – ta.speot.is Oct 02 '13 at 12:33