php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38753 function is not working as described
Submitted: 2006-09-08 19:21 UTC Modified: 2006-09-08 19:33 UTC
From: tigreverde at hotmail dot com Assigned:
Status: Not a bug Package: MySQLi related
PHP Version: 5.1.6 OS: XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: tigreverde at hotmail dot com
New email:
PHP Version: OS:

 

 [2006-09-08 19:21 UTC] tigreverde at hotmail dot com
Description:
------------
The code is supposed to able insert two values into a table, but it is not doing so.  There is something wrong between prepared stmt and mysql_stmt_bind_param.

Reproduce code:
---------------
<?php

// Make the connection.
$dbc = @mysqli_connect ('localhost', 'root', 'platypus', 'test') OR die ('Could not connect to MySQL: ' . mysqli_connect_error() );

// Make the query.
$query = "INSERT INTO accounts (name, balance) VALUES (?, ?)";

// Prepare the statement.
$stmt = mysqli_prepare($dbc, $query);

// Bind the variables.
mysqli_stmt_bind_param($stmt, 'sd', $name, $balance);

// Create an array of values to be inserted.
$data = array(
	array('Italo Calvino', 65465.99),
	array('Vladimir Nabokov', 132.74),
	array('James Joyce', 432.74),
	array('William Faulkner', 841664.67),
	array('F. Scott Fitzgerald', 69.23),
	array('Zora Neale Hurston', 130654.44),
	array('Franz Kafka', 87.63),
	array('William Carlos Williams', 9.98),
	array('Jane Austen', 1324.02),
	array('George Eliot', 49683.56)
);

// Print a caption.
echo "<p>The query being prepared is: $query</p>\n";

// Loop through the array, inserting each record.
foreach ($data as $record) {

	// Assign the variables.
	$name = $record[0];
	$balance = $record[1];
	
	// Execute the query.
	mysqli_stmt_execute($stmt);
	
	// Print the results.
	echo "<p>Name: $name<br />Balance: $balance<br />Result: ";
	// Print a message based upon the result.
	if (mysqli_stmt_affected_rows($stmt) == 1) {
		echo 'OK';
	} else {
		echo 'FAILED ' . mysqli_stmt_error($stmt);
	}
	
	echo '</p>';
	
} // End of foreach loop.


Expected result:
----------------
Name: Italo Calvino
Balance: 65465.99
Result: OK

Actual result:
--------------
Warning: mysqli_stmt_bind_param() [function.mysqli-stmt-bind-param]: Number of variables doesn't match number of parameters in prepared statement in c:\program files\apache group\Apache\htdocs\Ch11\prepared.php on line 21
The query being prepared is: INSERT INTO accounts (name, balance) VALUES (?, ?)
Name: Italo Calvino
Balance: 65465.99
Result: FAILED No data supplied for parameters in prepared statement


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-08 19:33 UTC] tony2001@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 17:01:31 2024 UTC