Prepared Statements - Search

From: Date: Fri, 14 Sep 2012 00:09:58 +0000
Subject: Prepared Statements - Search
Groups: php.db 
Request: Send a blank email to php-db+get-48497@lists.php.net to get a copy of this message
Dear List - Here is another problem I am having with prepared statements. The last one was INSERT, this one is SELECT. Here is the database: mysql> describe Intake3; +--------+-------------+------+-----+---------+-------+
| Field  | Type        | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| Site   | varchar(6)  | NO   | PRI |         |       |
| MedRec | int(6)      | NO   | PRI | NULL    |       |
| Fname  | varchar(15) | YES  |     | NULL    |       |
| Lname  | varchar(30) | YES  |     | NULL    |       |
| Phone  | varchar(30) | YES  |     | NULL    |       |
| Height | int(4)      | YES  |     | NULL    |       |
| Sex    | char(7)     | YES  |     | NULL    |       |
| Hx     | text        | YES  |     | NULL    |       |
| Bday   | date        | YES  |     | NULL    |       |
| Age    | int(3)      | YES  |     | NULL    |       |
+--------+-------------+------+-----+---------+-------+ 10 rows in set (0.00 sec) Here is my code: // Prepare statement
    $stmt = mysqli_stmt_init($cxn);
    $sql11 = "SELECT  'Fname', 'Lname', 'Phone', Height, Hx, Bday, Age FROM Intake3 where 1 and (MedRec = ?) and (Site = ?) and (Sex = ?)";
// Allocates and initializes a statement object suitable for mysqli_stmt_prepare().
// Prepare statement, bind result variables, execute and place results into bound result variables
mysqli_stmt_prepare($stmt, $sql11); mysqli_stmt_execute($stmt); mysqli_stmt_bind_result($stmt, $Site, $MedRec, $Fname, $Lname, $Phone, $Height, $Sex, $Hx, $Bday, $Age); //The error is in this statement.
    while (mysqli_stmt_fetch($stmt)) {
        printf("%s %s %s %s %s %s %s %s %s %s \n", $Site, $MedRec, $Fname, $Lname, $Phone, $Height, $Sex, $Hx, $Bday, $Age);
    }
I get no output from the printf statement. I receive the following error: Warning: mysqli_stmt_bind_result(): Number of bind variables doesn't match number of fields in prepared statement. The query, with the values inserted, works on the command line Help and advice, please. Ethan

« previous php.db (#48497) next »