简体   繁体   中英

echo single value from mysql table

I've been driving myself mad with this for the last hour. It should be so easy but I just cannot work it out:

All I am trying to do is echo 1 value (in column "active") from a mysql table where the column "name" is equal to "GSHP".

This is what I have. Can anyone please help?

$query = "SELECT active FROM discount WHERE name = GSHP";

        $result = mysql_query($query);

        $row = mysql_fetch_array($result);

        echo $row['active'];

In SQL you need to fit string literals into quotes. Your query should look like:

$query = "SELECT active FROM discount WHERE name = 'GSHP'";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM