Re: Re: Prepared Statements Insert Problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> if($stmt = mysqli_stmt_prepare($stmt, "INSERT INTO Intake3 (Site, MedRec, Fname, Lname, Phone, Height, Sex, Hx, Bday, Age) VALUES(?,?,?,?,?,?,?,?,?,?")!=0)

Let me break this into smaller chunks:

if ($a = $b != 0)

Precedence rules show that comparisons (!= in this case) come before
assignment (=).

So, what you're doing is this adding parens:

if ($a = ($b != 0) )

when, in fact, you want this:

if ( ($a = $b) != 0)

which is syntactically equivalent to:

if ( ($a = $b) )

This is the first part of your problem.

The second part, is that you are assigning to $stmt, which is what you
pass in the mysqli_stmt_prepare function, thus, after you've prepared
the statement, you overwrite it with the return value of the function,
which in procedural context, is either TRUE or FALSE, thus destroying
the work you just performed.

What you need here is:

$sql = "INSERT INTO Intake3
    (Site, MedRec, Fname, Lname,
     Phone, Height, Sex, Hx, Bday, Age)
    VALUES (?,?,?,?,?,?,?,?,?,?)";
if ( mysqli_stmt_prepare( $stmt,  $sql ) )
{
   // bind and process the stmt
}
else
{
   die('Error occured during statement prepare: ' .
       mysqli_stmt($stmt) );
}

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux