0

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'

ChrisRockGM
  • 325
  • 1
  • 5
  • 22

3 Answers3

1

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.

Emery King
  • 3,477
  • 20
  • 34
1

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());
}
ozz
  • 1,147
  • 7
  • 9
0
$query = mysql_query("SELECT about_me FROM users WHERE username = ".$mcu.""); 
if (!mysql_num_rows($query)) {
    die(mysql_error());
} 
subh
  • 78
  • 7