Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4111208
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:02:12+00:00 2026-05-20T22:02:12+00:00

<?php // Filter our input. $pID = filter_input(INPUT_GET, ‘pID’, FILTER_SANITIZE_NUMBER_INT); if(!$pID) { echo No

  • 0
<?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->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
// Prepare a statement to be executed.
// <http://us2.php.net/manual/en/pdo.prepare.php>
$sth = $pdo->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.
// <http://us2.php.net/manual/en/pdostatement.execute.php>
$sth->execute(array(
    $pID
));
// Did we get any results?
if($sth->rowCount() > 0) {
// Yes!  Fetch one row as an associative array.
// <http://us2.php.net/manual/en/pdostatement.fetch.php>
    $row = $sth->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);
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T22:02:13+00:00Added an answer on May 20, 2026 at 10:02 pm

    Let’s use PDO, the best built-in database adapter and the filter extension to protect our input.

    // Filter our input.
    $pID = filter_input(INPUT_GET, 'pID', FILTER_SANITIZE_NUMBER_INT);
    if(!$pID) {
        echo "No pID specified.";
        exit;
    }
    // You'll want to fill in the database name, and define the un/pw
    $pdo = new PDO('mysql:host=localhost;dbname=...', $username, $password);
    // Throw exceptions on errors.  You will need to catch these.
    $pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
    // Prepare a statement to be executed.
    // <https://www.php.net/manual/en/pdo.prepare.php>
    $sth = $pdo->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.
    // <https://www.php.net/manual/en/pdostatement.execute.php>
    $sth->execute(array(
        $pID
    ));
    // Did we get any results?
    if($sth->rowCount() > 0) {
    // Yes!  Fetch one row as an associative array.
    // <https://www.php.net/manual/en/pdostatement.fetch.php>
        $row = $sth->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);
    

    Whoops, try this order instead:

    $pdo = new PDO('mysql:host=localhost;dbname=...', $username, $password);
    $pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created a PHP class that envelopes filter_input functions to make our developer's life
My Drupal 6 installation has the php filter disabled so I can't use <?php
I am working on a filter functionality using ajax/jquery and php/mysql.I have two sets
With PHP, I'd like to use a preg_replace() filter for passwords such that the
I currently call a function to filter some HTML in PHP like this FilterHTML($string)
I am trying to filter/search a database with ajax $.ajax({ type: POST, url: filterSearch.php,
I'm trying to create a regular expressions that will filter valid emails using PHP
PHP_CodeCoverage 1.1 removed the singleton accessor for PHP_CodeCoverage_Filter that allowed our PHPUnit bootstrap.php files
I am using PHP filter to perfom basic sanitization and validation of form data.
I want to use the PHP Filter functions to quickly filter a form and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.