0

How do I check if a query has returned a value or not because this isn't working? I swear I have done it before but I can't work out why it isn't working.

echo "<form action = 'NoughtsAndCrosses.php' method = 'POST'>
        <input type = 'text' name = 'game_search'>
        <input type = 'submit' value = 'Search'>
    </form>
    ";

if(isset($_POST["game_search"])) {
    $game_search = $_POST["game_search"];
    if(!empty($game_search)) {
        $query = "SELECT `game_id` FROM `games` WHERE `game_id`='".$game_search."'";
        $query_run = mysql_query($query);
        $query_result = mysql_result($query_run, 0);
        echo $query_result;
        if(mysql_num_rows($query_run) != 0) {
            echo "Games found";
        } else {
            echo "No Games Found.";
        }

    }
}
3
Contributors
3
Replies
10
Views
4 Years
Discussion Span
Last Post by aVar++
1

I might be wrong, but I think your SQL Where clause should not test for game_id but rather for game_name or something similar no?

1

I agree with perlexed, it looks as though you're asking for a game_id when... well when you already have one?

SELECT `game_id` FROM `games` WHERE `game_id`=

I personally would use the SQL like function, because if the users search term doesn't match your predefined name EXACTLY, you'll get no results.

The MySQL LIKE operator will return results with a similar value to the submitted search term.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.