Justafriend Posted January 13, 2016 Share Posted January 13, 2016 Ok i have 2 issues i will start with the harder one first as it is more past my experties and i have spent time troubleshooting and cant get it solved i have 1 player name email address and 2 random numbers(ballots) that im trying to enter into my db after lengthy playing with the code i have 2 sql insert statements which will only grab the last one into the db Method 1 Steps i tried and results created 2nd table for the 2nd insert RESULT Only inserts to 2nd table echo only shows 2nd insert Method 2 name the sql insert to sql and sql1 same table RESULT gives me Warning: mysqli_multi_query() expects exactly 2 parameters, 3 given in but echos correctly Method 3 Name the sql insert to sql and sql1 different table Result gives me same warning and echos correctly Ideally i would like it to go into 2 rows in same table but am ok with having 2 separate table here is the code // Create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } $sql = "INSERT INTO ballot (username, useremail, randomnumber) VALUES ('".$_POST["username2"]."','".$_POST["email"]."','".$_POST["output"]."')"; $sql1 = "INSERT INTO bonus (username, useremail, randomnumber) VALUES ('".$_POST["username3"]."','".$_POST["email"]."','".$_POST["randomnumber3"]."')"; echo $sql ; if (mysqli_multi_query($conn, $sql, $sql1)) ; { echo "New records created successfully"; } mysqli_close($conn); ?> Quote Link to comment https://forums.phpfreaks.com/topic/300311-form-submission/ Share on other sites More sharing options...
requinix Posted January 13, 2016 Share Posted January 13, 2016 mysqli_multi_query() is not meant to work that way. Use the regular mysqli_query() and just call it twice for the two queries. Even better would be to use transactions: start transaction, do first query, rollback and abort if it fails, do second query, rollback and abort if it fails, commit. Quote Link to comment https://forums.phpfreaks.com/topic/300311-form-submission/#findComment-1529607 Share on other sites More sharing options...
Justafriend Posted January 13, 2016 Author Share Posted January 13, 2016 ok i am not sure if i have to do it via transactions i tried changing out the code to this // Create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } $sql = "INSERT INTO ballot (username, useremail, randomnumber) VALUES ('".$_POST["username2"]."','".$_POST["email"]."','".$_POST["output"]."')"; $sql1 = "INSERT INTO bonus (username, useremail, randomnumber) VALUES ('".$_POST["username3"]."','".$_POST["email"]."','".$_POST["randomnumber3"]."')"; if (mysqli_query($conn, $sql, $sql1)) ; mysqli_close($conn); { header("Location: http://justtheway.com/wb/events/pawn/Preregisterconfirm.html") ; } ?> and i get it redirected to submission page BUT it is only entering into the bonus table not the ballot table Quote Link to comment https://forums.phpfreaks.com/topic/300311-form-submission/#findComment-1529609 Share on other sites More sharing options...
Solution requinix Posted January 13, 2016 Solution Share Posted January 13, 2016 Use the regular mysqli_query() and just call it twice for the two queries. Not both at once. One at a time. Because if you read the documentation for mysqli_query() you would know what the arguments to it are and that it only does one query. Quote Link to comment https://forums.phpfreaks.com/topic/300311-form-submission/#findComment-1529612 Share on other sites More sharing options...
Justafriend Posted January 14, 2016 Author Share Posted January 14, 2016 thank you very much for your help Quote Link to comment https://forums.phpfreaks.com/topic/300311-form-submission/#findComment-1529646 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.