November 18, 20169 yr Hello, I went through all the links available in Google but didn't found any correct solution. Please help the noob here. Also if you find that I am thinking totally in a wrong way then please suggest the correct way. I want to know that how thing is actually done. I have created two tables so that I can do RDBMS (Data Normalization and Joining). Here is my code: <?php require("conn.php"); // Escape user inputs for security $name = mysqli_real_escape_string($conn, $_POST['name']); $desc = mysqli_real_escape_string($conn, $_POST['desc']); $cars = mysqli_real_escape_string($conn, $_POST['cars']); $gender = mysqli_real_escape_string($conn, $_POST['gender']); $bike = mysqli_real_escape_string($conn, $_POST['bike']); $cycle = mysqli_real_escape_string($conn, $_POST['cycle']); // attempt insert query execution $sql = "INSERT INTO tbl_project2 (Name, Description, Cars, Gender, Own) VALUES ('$name', '$desc', '$cars', '$gender', '$bike' )"; $sql = "INSERT INTO tbl_project2b (Cycle) VALUES ('$cycle' )"; if(mysqli_query($conn, $sql)){ echo "Records added successfully."; } else{ echo "ERROR: Could not able to execute $sql. " . mysqli_error($conn); } // close connection mysqli_close($conn); ?> Whatever I try nothing works. I tried mysqli multi_query but its also not working. My code only saves data to the 2nd table and not in the 1st table. So what is the correct method of adding data simultaneously into two or more tables? Thank you. Edited November 18, 20169 yr by dsouravs
November 18, 20169 yr Author Problem solved. http://stackoverflow.com/questions/30466422/insert-data-into-multiple-tables-using-one-form
December 6, 20169 yr You can use stored Procedure. Wrap the insert statements in stored procedure and call that procedure like create procedure insert_multiple as begin insert into table1... insert into table2... end
Create an account or sign in to comment