Error statement:
Warning: mysql_num_rows() expectations parameter 1 to be resource, boolean give in/Applications/XAMPP/xamppfiles/htdocs/testsite/search.phponline33
What is the cause?
<html>
<head>
</head>
<body>
<center>
<form method="get" action="search.php">
<input type="text" name="search">
<input type="submit" name="submit" value="search database">
</form>
</center>
<hr of >
<?php
if(isset($_REQUEST['submit'])){
$search=$_GET['search'];
$terms=explode(",$search);
$query="SELECT* FROM users WHERE";
$i = 0;
foreach($terms as$each){
$i++;
if($i==1){
$query.="name LIKE'%each%'";
} else{
$query.="OR name LIKE'%each%'";
}
}
mysql_connect("localhost", "root", "") or die("problem with connection...");
mysql_select_db("testsite");
$query=mysql_query($query);
$num = mysql_num_rows($query);
if($num>0&&$search!=""){
while($row=mysql_fetch_assoc($query)){
$id = $row ['id'];
$name = $row ['name'];
$email=$row['email'];
$password=$row['password'];
echo "$name<br/>$email<br/>";
}
} else{
echo "No results found";
} mysql_close();
} else{
echo "Please type any word...";
}
?>
</body>
</html>
SQL build seems to be failing.
This is
$query="SELECT* FROM users WHERE";
Place half-width space behind WHERE
$query="SELECT* FROM users WHERE";
© 2024 OneMinuteCode. All rights reserved.