我想将数据插入四个表。我可以这样做吗? [关闭]
hi all i want to insert data into four tables how can i do.so far i write code to insert data into two tables .now am unable to insert data into four tables.please help me to do .below is my code
this code is am inserting data through post .i am inserting data into two tables perfectley but am unable to insert data into four tables .all the four tables have common id usr_id
$_POST = json_decode(file_get_contents('php://input'), true);
if (isset($_POST['nric'],$_POST['id'],$_POST['fullname'],$_POST['gender'],$_POST['password'],$_POST['address'],$_POST['postcode'],$_POST['state'],$_POST['contact1'],$_POST['email'])) {
global $db;
$db = mysqli_connect("localhost", "root", "", "asklms");
if($db === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$nric=mysqli_real_escape_string($db,$_POST["nric"]);
$id =(int)$_POST["id"]; $fullname=mysqli_real_escape_string($db,$_POST["fullname"]);
$gender=mysqli_real_escape_string($db,$_POST["gender"]);
$address=mysqli_real_escape_string($db,$_POST["address"]); $postcode=mysqli_real_escape_string($db,$_POST["postcode"]);
$state=mysqli_real_escape_string($db,$_POST["state"]); $expirydate=mysqli_real_escape_string($db,$_POST["expirydate"]); $contact1=mysqli_real_escape_string($db,$_POST["contact1"]); $email=mysqli_real_escape_string($db,$_POST["email"]);
query 1 to insert data into usr_data ::
$sql1 ="INSERT INTO usr_data (login,usr_id, firstname, gender, street, zipcode, country, phone_mobile, email) VALUES ('$_POST[nric]','$_POST[id]','$_POST[fullname]','$_POST[gender]','$_POST[address]','$_POST[postcode]','$_POST[state]','$_POST[contact1]','$_POST[email]')
ON DUPLICATE KEY UPDATE login='$_POST[nric]',usr_id='$_POST[id]',firstname='$_POST[fullname]',gender='$_POST[gender]',street='$_POST[address]',zipcode='$_POST[postcode]',country='$_POST[state]',phone_mobile='$_POST[contact1]',email='$_POST[email]'";
$sql ="INSERT INTO `object_data` ( `obj_id`, `type`, `owner`) VALUES ('$_POST[id]','usr','-1')
ON DUPLICATE KEY UPDATE obj_id='$_POST[id]',type='usr'
";
$sql2 ="INSERT INTO `udf_text` ( `obj_id`) VALUES ('$_POST[id]')
";
$sql3 ="INSERT INTO `role_data` ( `role_id`, `allow_register`, `assign_users`,`auth_mode`,`disk_quote`,`wsp_disk_quota`) VALUES ('$_POST[id]','0','0','default','0','0')
";
$update1 = mysqli_query($db,$sql1);
// dd($update1);
$update2 = mysqli_query($db,$sql);
$update3 =mysqli_query($db,$sql2);
$update4 =mysqli_query($db,$sql3);
i wrote like this but data inserting to only two tables i want to insert data into four tables how can i do.so far i write code to insert data into two tables .now am unable to insert data into four tables.please help me to do i want to insert data into four tables how can i do.
If you are able to insert data into two columns, then you should also able to do that for other two as well. But you said it's not happening.
In this scenario, there is a high chance that you may have some error in your statements like there is some mistake typing of column names of table names etc.
So go through your statements again.
One more remedy is there, you make echo your query statements which are not working, and do paste them on the server in mysql directly.There you will be able to clearly see the errors.
Do let me know if you are able to see any error or do some inspection and be specify the problem.