Click here to Skip to main content
15,916,452 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I dont understand why i get the above error


if($_POST['agentdetailsbtn'] && $_POST['propertynum']) {


$propnumber = $_POST['propertynum'];

echo('<table class="table table-striped" border="1" >'."\n");

$sql = "SELECT Property_number, buildingtype, Address, agent_id FROM property WHERE Property_number = ':propertynumber'";
			$stmt = $pdo->prepare($sql);
			$stmt->execute(array( 
			':propertynumber' => $propnumber
	
			 )); 


  
while ( $row = $stmt->fetch(PDO::FETCH_ASSOC) ) {

echo"<tr class= 'table-success' border='1'><th>";
    echo("Property Number");
    echo("</th><th>");


What I have tried:

$sql = "SELECT buildingtype, Address, agent_id FROM property WHERE Property_number = ':propertynumber'";
$stmt = $pdo->prepare($sql);
$stmt->execute(array(
':propertynumber' => $_POST['propertynum']
Posted
Updated 19-Jun-22 23:12pm
Comments
Richard MacCutchan 19-Jun-22 4:21am    
Try removing the single quotes around ':propertynumber'. It is supposed to be a parameter key, not a literal value.
Richard Deeming 20-Jun-22 5:04am    
You should post this as a solution. :)
Richard MacCutchan 20-Jun-22 5:09am    
I wasn't 100% certain that it was the answer, but thanks I will do so.

1 solution

PHP
$sql = "SELECT Property_number, buildingtype, Address, agent_id FROM property WHERE Property_number = ':propertynumber'";

The single quotes around ':propertynumber', means that PHP will treat it as a string literal and not as a parameter keyword. Change the code to:
PHP
$sql = "SELECT Property_number, buildingtype, Address, agent_id FROM property WHERE Property_number = :propertynumber";

so the keyword will be recognised as such.
 
Share this answer
 

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



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