MySQL query not working while using php variable in where clause

后端 未结 3 1122
忘了有多久
忘了有多久 2021-01-23 16:02

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

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-23 16:45

    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.

提交回复
热议问题