I have created a script so users can save their favourite games in a mysql database.
The script works by using the URL to decide which game to add to the database. For examplt http://www.website.com/add.php?game=1 each game has a unique ID which is how the game is added by using the ID in the URL like in the example. Basically what I want to do is to only allow the game to be added into the database if the game actually exists. How can I check wether the number in the URL exists with the games ID's in the database. For example if there are only 45 games in the database and a user types the URL http://www.website.com/add.php?game=46 it would show an error.
I would think that I should need something such as:
Code: Select all
<?php
$game = mysql_real_escape_string($_GET['game']);
if ($game = CODE NEEDED)??
echo "Game does not exist!";
else MY INSERT CODE HERE ?>