如何在PHP中使用MySQL获取单个单元格? [重复]

Whenever I try to run some code to get a specific cell, I get an error. Here is the code:

        <?php
            $query = mysql_query("SELECT about_me FROM users WHERE username = '" . $mcu . "'");
            if($query === FALSE) {
        die(mysql_error()); // TODO: better error handling
    }

    while($row = mysql_fetch_array($query))
    {
        $abme = mysql_num_rows($query);
    }
        ?>
        About Me:<p> <?php echo "$abme" ?></p>

Here is the error:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in location/to/file.php on line 96

Line 96 is the $row = mysql_fetch_array($query);.

I did a die check and it says Unknown column 'user_name_here' in 'where clause'

</div>

Try this:

$query = mysql_query("SELECT about_me FROM users WHERE username = '" . $mcu . "'");

It's because you didn't quote the parameter.

Also, you should wrap your parameter in mysql_real_escape_string() or switch to mysqli or PDO to protect you application from SQL injection attacks.

Sounds like your $query is false, meaning that mysql_query() failed. You probably have a bad SQL query.

$query = mysql_query("SELECT about_me FROM users WHERE username = ".$mcu.""); 
if (!$query) {
    die(mysql_error());
}
$query = mysql_query("SELECT about_me FROM users WHERE username = ".$mcu.""); 
if (!mysql_num_rows($query)) {
    die(mysql_error());
}