Click here to Skip to main content
15,920,217 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have the following code:
PHP
$stmt="SELECT state FROM branch_info WHERE state = ? AND branch = ?";
							
if($stmt === false)
{
	trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $conn->errno . ' ' . $conn->error, E_USER_ERROR);
}
$param1=$_POST["states"];
$param2=$_POST["exstbr"];
$stmt->bind_param('ss',$param1,$param2);
$stmt->execute();
$result = $stmt->get_result();
while($row = $result->fetch_array(MYSQLI_ASSOC))
{
	if($row["state"] > 0)
		echo "Already Exists";
}
$stmt->close();

I got the following error:
PHP
Fatal error: Call to a member function bind_param() on string in C:\---------------------------------------------- on line 60

Kindly help in this regard. Its urgent. Thanks in advance.

What I have tried:

I have tries to pass in the parameters directly it didnt work.
I used echo $param1; and echo $param2 to check the values presence before bind_param() statement and the values are echoed fine on the web page.
I also tried
$stmt->bind_param("ss", $param1, $param2);
but no wonders.
Posted
Updated 11-Jul-16 4:33am
v2

1 solution

Hi,

You missed to prepare the statement. Please try below code.

$stmt = $conn->prepare("SELECT state FROM branch_info WHERE state = ? AND branch = ?");
							
if($stmt === false)
{
	trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $conn->errno . ' ' . $conn->error, E_USER_ERROR);
}

$param1=$_POST["states"];
$param2=$_POST["exstbr"];
$stmt->bind_param('ss',$param1,$param2);
$stmt->execute();
$result = $stmt->get_result();

while($row = $result->fetch_array(MYSQLI_ASSOC))
{
	if($row["state"] > 0)
		echo "Already Exists";
}

$stmt->close();


Hoping $conn is your connection object and it should look like below.

C#
$conn = new mysqli($servername, $username, $password, $dbname);


Hope this will help you :).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900