Calling Fields based on id= in url - Php
<pre><code>&lt;?php
// Filter our input.
$pID = filter_input(INPUT_GET, 'pID', FILTER_SANITIZE_NUMBER_INT);
if(!$pID) {
    echo "No pID specified.";
    exit;
}
// Throw exceptions on errors.  You will need to catch these.
PDO::setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$username = "##";
$password = "##";
// You'll want to fill in the database name, and define the un/pw
$pdo = new PDO('mysql:host=localhost;dbname=dbname', $username, $password);
$pdo-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
// Prepare a statement to be executed.
// &lt;http://us2.php.net/manual/en/pdo.prepare.php&gt;
$sth = $pdo-&gt;prepare('
    SELECT fname, lname
      FROM Professor
     WHERE pID = ?
');
// Execute the prepared statement.  The values in the array are
// automatically escaped and quoted, and placed where the question
// marks are in the prepared statement.  *Used correctly*, this method
// makes you immune from SQL Injection.
// &lt;http://us2.php.net/manual/en/pdostatement.execute.php&gt;
$sth-&gt;execute(array(
    $pID
));
// Did we get any results?
if($sth-&gt;rowCount() &gt; 0) {
// Yes!  Fetch one row as an associative array.
// &lt;http://us2.php.net/manual/en/pdostatement.fetch.php&gt;
    $row = $sth-&gt;fetch(PDO::FETCH_ASSOC);
    echo "I found {$row['fname']} {$row['lname']}.";
} else {
// Nope, let the user know we found nothing.
    echo "No results.";
}
unset($sth);
?&gt;
</code></pre>
