Database query gives no error either no result?
Hello my code does not give any error but not result of a name thats in db ? the code is the following for the form to process the data the user inputs to the php file. HTML User input code:
<html>
<head>
</head>
<body>
<form action="se开发者_高级运维arch.php">
<input type="text" name="search">
<input type="submit">
</body>
</html>
Php code:
<?php
$db = new mysqli("localhost","root","","acksocial");
if(mysqli_connect_error())
{
printf("Connection failed:%s \n",mysqli_connect_error());
exit();
}
$name = mysqli_real_escape_string($db, $_POST['search']);
$table = 'acksearch';
if($result = $db->query("SELECT * FROM $table WHERE name = $name", MYSQLI_ASSOC))
{
while($row = $result->fetcssh_object())
{
// $row is an associative array
// Do something here
echo "Name: ".$row['name'];
echo " country: ".$row['country'];
}
}
$db->close();
?>
mysqli_real_escape_string
escapes the string, but doesn't quote it, so your query has a syntax error.
Replace it with:
"... WHERE name = '$name'"...
Please check for and report (or log, or whatever) errors when using database functions.
精彩评论