Reputation: 1
I have got a problem with testing out if a string exists in my database!
This is what I've got so far:
$db = mysqli_connect("localhost", "database", "secret", "user");
if(!$db)
{
exit("Error: ".mysqli_connect_error());
}
$search = 'SELECT * FROM table WHERE ip = $client_ip';
$result = mysqli_query($db, $search);
while($row = mysqli_fetch_object($result)) {
if (isset($row->blocked)) {
echo 'You are blocked!';
} else {
echo 'You are not blocked!';
}
But this won't work for me. $client_ip is defined correctly before.
Upvotes: 0
Views: 78
Reputation: 35
try this one :
$search = "SELECT * FROM table WHERE ip = '{$client_ip}'";
Upvotes: 0
Reputation: 219894
You need to wrap $client_ip
in quotes as it is a string:
$search = "SELECT * FROM table WHERE ip = '$client_ip'";
Upvotes: 3