Re: [PHP-DB] Prepared Statements - Search

2012-09-13 Thread Karl DeSaulniers

Ethan,
9 times out of 10 your answer is in the error statement.

Warning: mysqli_stmt_bind_result(): Number of bind variables doesn't  
match number of fields in prepared statement.


GL,

Best,
Karl


On Sep 13, 2012, at 7:09 PM, Ethan Rosenberg, PhD wrote:


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


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



Karl DeSaulniers
Design Drumm
http://designdrumm.com



[PHP-DB] Prepared Statements - Search -- SOLVED!!!

2012-09-13 Thread Ethan Rosenberg, PhD

Dear List -

-->> THANKS TO ALL. See below <--

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

***


Here is my revised code:

// Prepare statement
$stmt = mysqli_stmt_init($cxn);
$sql11 = "SELECT  MedRec, Site, Sex,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_bind_param($stmt, 'iss', $_POST['MedRec'], 
$_POST['Site'], $_POST['Sex']);

  mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $MedRec, $Site, $Sex, $Fname, 
$Lname, $Phone, $Height, $Hx, $Bday, $Age);

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);

}

Added the bind_parameters statement and it worked.  Stupid me - you 
can’t perform a query unless the parameters have been inserted into the 
query.


Live and learn.


Ethan

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



Re: [PHP-DB] Re: Problems w/ insert -- SOLVED!!!

2012-09-13 Thread Jim Giner

On 9/13/2012 9:15 PM, Ethan Rosenberg, PhD wrote:

Dear list -

Thanks to all.  It now works!

The problem, as you correctly noted, was the erroneous inclusion of the
bind-results statement.  Removed that and it  worked!!

Thanks again!

Ethan

Methinks Ethan is thanking the group for assistance on his PREVIOUS 
problem with the prepared INSERT query.


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



Re: [PHP-DB] Re: Problems w/ insert -- SOLVED!!!

2012-09-13 Thread Ethan Rosenberg, PhD

Dear list -

Thanks to all.  It now works!

The problem, as you correctly noted, was the erroneous inclusion of the 
bind-results statement.  Removed that and it  worked!!


Thanks again!

Ethan


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



Re: [PHP-DB] Prepared Statements - Search

2012-09-13 Thread Fjalar Sigurðarson
Does the list of the SELECT fields not have to match the variables you are
binding? E.g. if you do not include MedRec in your SELECT then you have no
MedRec data to bind from your $sql11 variable to the $MedRec varable and
then nothing to print there... or what? Am I just fabulating? :).

Cheers,

Fjalar

On Friday, September 14, 2012, Ethan Rosenberg, PhD
wrote:

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
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php



On Friday, September 14, 2012, Ethan Rosenberg, PhD wrote:

> 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
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


[PHP-DB] Prepared Statements - Search

2012-09-13 Thread Ethan Rosenberg, PhD

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


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