0

Please help! i am troubling about on how can i execute my sql script properly. Thanks!Here's my code

$sql="INSERT INTO inventory(account_number,serial_number,locator,remarks,`date_assigned`) VALUES('$accountno','$serial','$locator','$remarks',NOW())";
$sql.="INSERT INTO action_log(action,username,`date`) VALUES ('assigns the box($serial) to $accountno','$user',NOW())";
$sql.="INSERT INTO account_logs(action_log,account_number,username,`date`) VALUES('Assign','$accountno','$user',NOW())";
  if(mysql_query($sql)){echo "Successfully Assigned!";}
    else{echo "Insertion Failed!";}
4
Contributors
5
Replies
18
Views
3 Years
Discussion Span
Last Post by Jemuel
2

mysql_query does not allow multiple queries to be sent at once. If you want to use this feature, I suggest you switch to MySQLi where you can use mysqli_multi_query

0

Hope this helps

$sql1="INSERT INTO inventory(account_number,serial_number,locator,remarks,`date_assigned`) VALUES('$accountno','$serial','$locator','$remarks',NOW())";
$sql2="INSERT INTO action_log(action,username,`date`) VALUES ('assigns the box($serial) to $accountno','$user',NOW())";
$sql3="INSERT INTO account_logs(action_log,account_number,username,`date`) VALUES('Assign','$accountno','$user',NOW())";
  //run query 1 
  if(mysql_query($sql1)){echo "Successfully inventory Assigned!";}
    else{echo "Insertion inventory Failed!";}
  //run query 2 
  if(mysql_query($sql2)){echo "Successfully action_log Assigned!";}
    else{echo "Insertion action_log Failed!";}
  //run query 3 
  if(mysql_query($sql3)){echo "Successfully account_logs Assigned!";}
    else{echo "Insertion account_logs Failed!";}

Or:

 $sql1="INSERT INTO inventory(account_number,serial_number,locator,remarks,`date_assigned`) VALUES('$accountno','$serial','$locator','$remarks',NOW())";
   $sql2="INSERT INTO action_log(action,username,`date`) VALUES ('assigns the box($serial) to $accountno','$user',NOW())";
   $sql3="INSERT INTO account_logs(action_log,account_number,username,`date`) VALUES('Assign','$accountno','$user',NOW())";

    mysql_query($sql1) 
    or die 
    ("<br><br>Error: ". mysql_error().""); 
    mysql_query($sql2) 
    or die 
    ("<br><br>Error: ". mysql_error().""); 
    mysql_query($sql3) 
    or die 
    ("<br><br>Error: ". mysql_error().""); 
0

Thanks for the reply sir! The First script is good but the only prblem I see when I submit it, it prints all the success messages. Can you modify a little the first script? Thanks for the help!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.