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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:25:53+00:00 2026-06-13T20:25:53+00:00

I know i should be using prepare statements and sanitizing the data i’m just

  • 0

I know i should be using prepare statements and sanitizing the data i’m just checking the PDO driver

I just want to know why if i’m passing just random data the query returns true?

just notice this PDO::query — Executes an SQL statement, returning a result set as a PDOStatement object

    $dbuser = 'root';
$dbpass = 'root';
$formpost = false;
try
{
    $dbh = new PDO('mysql:host=127.0.0.1;dbname=loginexample', $dbuser, $dbpass);
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}
if(!empty($_POST['username']) && !empty($_POST['password']))
{
    $formpost = true;
    $username = $_POST['username'];
    $password = $_POST['password'];
}

if($dbh && $formpost)
{
    $sql= "SELECT username, password FROM user WHERE username='$username' AND password='$password'";
    if($dbh->query($sql))
    {
        echo 'true';
    }
}
  • 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-06-13T20:25:54+00:00Added an answer on June 13, 2026 at 8:25 pm

    This line: if($dbh->query($sql)) might not return an object that contains any found records, but it returns an object nonetheless. An object that might tell you that the number of found rows equals zero, for instance.

    Try returning true or false based on the number of found records….

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

Sidebar

Related Questions

I want to query my MySQL database using prepared statements. The query should look
I know you should use POST whenever data will be modified on a public
I know you should use a StringBuilder when concatenating strings but I was just
Firstly, I know I should be using proper Threading techniques (Threadpool, BeginInvoke, etc.) to
I'm trying to figure out Win8 C# threading, I know I should be using
I have some pages that make PDO queries using prepare() and execute() (binding some
Using aspnet 3.5. Here is my code. Yes I know I should be using
First you should know I have looked into many questions and none of them
i know it should be context. what exactly is a context though. usually when
I know I should write this in Vb.net but for my own reasons I'm

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.