0

I have a simple SELECT statement that I'm using in PHP:

$vote=mysql_query("SELECT * FROM `votes` where username = '$big_hand_username' AND 
`voter` = '$user_name'");

When using this statement I don't get any rows returned. I should get 1 row returned. I only have one row in the votes table and it contains the username field that matches variable $big_hand_username. $big_hand_username & $user_name both contain data and I've echoed them out to make sure.

However, when I just select all from votes table I get 1 row returned, which you'd expect. I can also select all from another table using the same variable:

$vote=mysql_query("SELECT * FROM `users` where username = '$big_hand_username'");

This returns 1 row, which you'd expect as it contains a row containing the matching the field username.

I just can't understand why I can't get a row returned from votes table using the first select statement. Am I missing something? Could it be something to do with construction of the table? I've also tried running through while loop after the select statement but can't see anything wrong. Any pointers would be helpful.

4

3 回答 3

2

尝试这个

$vote=mysql_query("SELECT * FROM `votes` where username = '".$big_hand_username."' AND 
voter = '".$user_name."'");
于 2012-12-05T13:15:22.237 回答
0

尝试波纹管

$sql="
        SELECT * FROM votes 
        WHERE username = '{$big_hand_username}' 
        AND voter = '{$user_name}'
    ";
echo $sql; // for debuging also user_name,big_hand_username check
// for preventing sql-injection
$vote=mysql_query($sql);
于 2012-12-05T13:54:29.123 回答
0

尝试这个

$vote = mysql_query("
            SELECT * FROM votes 
            WHERE username = '{$big_hand_username}' 
            AND voter = '{$user_name}'
        ");
于 2012-12-05T13:34:50.013 回答