0

I want to check if the address record is already exists or not and I am using simple query which should will return the value of existed records in database but instead of that it uses the keyword to search for columns this is my code :

$address=$_POST['billing_address_2'];
$query = "select * from shipping_info WHERE address=$address";
$st2  = $con->prepare($query);
        $st2->execute();

this is the exact error message : Column not found: 1054 Unknown column 'ffff' in 'where clause'. note : 'ffff' is the value of $address variable

ibrahim
  • 135
  • 3
  • 9

1 Answers1

1

The error is because you didn't put quotes around $address.

But you should use a parametrized query.

mysqli:

$address=$_POST['billing_address_2'];
$query = "select * from shipping_info WHERE address=?";
$st2  = $con->prepare($query);
$st2->bind_param("s", $address);
$st2->execute();

PDO:

$address=$_POST['billing_address_2'];
$query = "select * from shipping_info WHERE address=:address";
$st2  = $con->prepare($query);
$st2->bindParam(":address", $address);
$st2->execute();
Barmar
  • 741,623
  • 53
  • 500
  • 612