I\'m new to PHP and MySQL. I am trying to make a simple search form using which I would want to show the results from the database based on the input text entered in the form. M
This should work:
$query = "SELECT * FROM cats
WHERE name = '$name'";
Also, when you call "exit;" in the following block it will cancel the execution of the rest of your script:
if (!empty($results)){
echo "query successful" ;
exit;
}
You're escaping the $
in the variable by doing \$
.
Try:
$query = "SELECT * FROM `cats` WHERE name='$name'";
EDIT
From the discussion below.
The problem with the undefined index
is the fact that you are using $row['age']
when really, the column name in the database is Age
. Therefore you must use $row['Age']
when referring to the item. The same goes for name
.
$query = "SELECT * FROM `cats` WHERE name='" . $name . "'";
or without concatenation
$query = "SELECT * FROM `cats` WHERE name='$name'";