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

  • Home
  • SEARCH
  • 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 709813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:32:42+00:00 2026-05-14T04:32:42+00:00

I’ve come upon a rather interesting thing, which I can’t seem to figure out

  • 0

I’ve come upon a rather interesting thing, which I can’t seem to figure out myself.
Everytime when executing a SQL statement which contains a ‘… AND …’ the result is empty.

Example:

echo('I have a user: ' . $email . $wachtwoord . '<br>');

$dbh = new PDO($dsn, $user, $password);

$sql = 'SELECT * FROM user WHERE email = :email AND wachtwoord= :wachtwoord';
$stmt = $dbh->prepare($sql);
$stmt->bindParam(:email,$email,PDO::PARAM_STR);
$stmt->bindParam(:wachtwoord,$wachtwoord,PDO::PARAM_STR);

$stmt->execute();

while($row = $stmt->fetchObject())
{   
  echo($row->email . ',' . $row->wachtwoord);
  $user[] = array(
    'email' => $row->email,
    'wachtwoord' => $row->wachtwoord
  );
}

The first echo displays the correct values, however the line with

echo($row->email . ',' . $row->wachtwoord);

is never reached.
A few things I want to add:
1) I am connected to the database since other queries work, only the ones where I add an ‘AND’ after my ‘WHERE’s fail.
2) Working with the while works perfectly with queries that do not contain ‘… AND …’
3) Error reporting is on, PDO gives no exceptions on my query (or anything else)
4) Executing the query directly on the database does give what I want:

SELECT * FROM user WHERE email = 'jurgen@email.com' AND wachtwoord = 'jurgen'

I can stare at it all day long again (which I already did once, but I managed to work around the ‘AND’), but maybe one of you can give me a helping hand.

Thank you in advance.

Jurgen

  • 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-14T04:32:43+00:00Added an answer on May 14, 2026 at 4:32 am

    Let’s see if one of those debug queries

    ....
    $dbh = new PDO($dsn, $user, $password);
    
    function debugQuery($dbh, $querystring, $params) {
      $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);  
      $stmt = $dbh->prepare($querystring);
      $stmt->execute($params);
      echo $querystring, ":<br />\n";
      while ( false!== ($row=$stmt->fetch(PDO::FETCH_ASSOC)) ) {
        echo '  ', join(', ', $row), "<br />\n";
      }
    }
    
    debugQuery($dbh, 'SELECT Count(*) as c FROM user', array());
    debugQuery($dbh, 'SELECT Count(*) as c FROM user WHERE email=?', array($email));
    debugQuery($dbh, 'SELECT Count(*) as c FROM user WHERE wachtwoord=?', array($wachtwoord));
    debugQuery($dbh, 'SELECT Count(*) as c FROM user WHERE email=? AND wachtwoord=?', array($email, $wachtwoord));
    debugQuery($dbh, 'SELECT Count(*) as c FROM user WHERE email LIKE ? AND wachtwoord LIKE ?', array( '%'.trim($email).'%', '%'.trim($wachtwoord).'%'));
    
    $sql = 'SELECT * FROM user WHERE email = :email AND wachtwoord= :wachtwoord';
    $stmt = $dbh->prepare($sql);
    ...
    

    returns something interesting.

    edit: Doesn’t seem so… then let’s attack this from another angle

    $email = 'emailA';
    $wachtwoord = 'wachtwoordA';
    echo('I have a user: ' . $email . $wachtwoord . '<br>');
    
    //$dbh = new PDO($dsn, $user, $password);
    $dbh = new PDO("mysql:host=localhost;dbname=test", 'localonly', 'localonly'); 
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    // create a temporary table
    $dbh->exec('CREATE TEMPORARY TABLE tmp_user ( id int auto_increment, email varchar(32), wachtwoord varchar(32), primary key(id))');
    // and fill in exactly the record we're looking for
    $dbh->exec("INSERT INTO  tmp_user (email, wachtwoord) VALUES ('$email', '$wachtwoord')");
    
    
    $sql = 'SELECT * FROM tmp_user WHERE email = :email AND wachtwoord= :wachtwoord';
    $stmt = $dbh->prepare($sql);
    $stmt->bindParam(':email', $email,PDO::PARAM_STR);
    $stmt->bindParam(':wachtwoord', $wachtwoord,PDO::PARAM_STR);
    
    $stmt->execute();
    
    while($row = $stmt->fetchObject())
    {   
      echo($row->email . ',' . $row->wachtwoord);
      $user[] = array(
        'email' => $row->email,
        'wachtwoord' => $row->wachtwoord
      );
    }
    

    prints I have a user: emailAwachtwoordA<br>emailA,wachtwoordA on my version of php/mysql.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.