Re: Re: Prepared Statements Insert Problem

From: Date: Mon, 03 Sep 2012 00:26:20 +0000
Subject: Re: Re: Prepared Statements Insert Problem
References: 1 2 3 4  Groups: php.db 
Request: Send a blank email to php-db+get-48454@lists.php.net to get a copy of this message
> 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) ); }

« previous php.db (#48454) next »