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!";}

What's going wrong? :)

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

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().""); 

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!

Thanks for the replies, it helps me a lot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.