Jump to content

form submission


Justafriend
Go to solution Solved by requinix,

Recommended Posts

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);
 ?> 
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Solution

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.