How do I check if an id in a query string is valid?
<p>I am passing a database generated id value in a link to another page. In the receiving page where I call <code>$_GET</code>, I want to protect against people inserting bogus values after the <code>?</code> in the url (e.g. www.mysite.com?id=43). </p>

<p>I want to check the incoming value and make sure it's a valid id from the database, or is there a way to just check the value for NULL or empty? This is what I've tried:</p>

<p>Source page:</p>

<pre><code> echo "&lt;a href=\"get-post-pg2.php?id=" .urlencode($row['id']) ."\"&gt;Second Page&lt;/a&gt;";
</code></pre>

<p>Target page:</p>

<pre><code>$id = $_GET['id'];
if(isset($_GET)) {
    echo $id;
} else
    echo 'foo';
}
</code></pre>
