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 6724385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:41:02+00:00 2026-05-26T09:41:02+00:00

I am trying to take a variable passed from another page and use it

  • 0

I am trying to take a variable passed from another page and use it in a PDO query. The variable is the date the record was added and I’m trying to return all the newer records. Do I use $_POST for this in PDO?

<?php
require_once('globals.php');

$date_added = $_POST['date_added'];

$sth = $dbh->prepare("SELECT * FROM games WHERE date_added > $date_added");
$sth->execute();

/* Fetch all of the remaining rows in the result set */
print("Fetch all of the remaining rows in the result set:\n");
$result = $sth->fetchAll();
print_r($result);


?>
  • 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-26T09:41:02+00:00Added an answer on May 26, 2026 at 9:41 am

    You need to actually establish a connection to the database by creating a new PDO object into $dbh. The code below assumes a database user and password as $dbusername, $dbpassword and database named $nameofdb.

    $date_added is replaced in the prepare() call with a parameter :dateadded, then passed via an array to the execute() call.

    Please read the documentation on both PDO::__construct() and PDO::execute()

    <?php
    require_once('globals.php');
    
    // Connect to MySQL via PDO
    try {
        $dbh = new PDO("mysql:dbname=$nameofdb;host=localhost", $dbusername, $dbpassword);
    } catch (PDOException $e) {
        echo 'Connection failed: ' . $e->getMessage();
    }
    
    $date_added = $_POST['date_added'];
    
    // Replace `$date_added` with a parameter `:dateadded`
    $sth = $dbh->prepare("SELECT * FROM games WHERE date_added > :dateadded");
    // bind $date_added and pass it into the execute() call inside an array
    $sth->execute(array('dateadded'=>$date_added));
    
    /* Fetch all of the remaining rows in the result set */
    print("Fetch all of the remaining rows in the result set:\n");
    $result = $sth->fetchAll();
    print_r($result);
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to take a variable from a php page and send it to
I'm trying to take a variable from the parent movieclip and use it in
I am trying to take a variable sent from flash, and save it to
I am trying to take a variable from $_POST , run mysql_real_escape_string and a
So I'm trying to take a variable size (anywhere from a few MBs to
I'm trying to take two 7 digit numbers (source and target record counts) and
I am trying to take a PHP variable and pass it along to Flash
I'm trying to take the contents of a folder and copy it to another
I'm trying to take a variable (long), and convert it to a string, such
So I'm trying to take the variable that increments in a for statement, 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.