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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:15:02+00:00 2026-06-10T01:15:02+00:00

Another newbie here.. I’m trying to fix below code to prevent sql injection and

  • 0

Another newbie here..
I’m trying to fix below code to prevent sql injection and learn the new way of writing php and sql.

Your kindly advise would be greatly appreciated.

I modified this

<?php

class DB_Functions {

    private $db;

    function __construct() {

        require_once 'db_connect.php';

        $this->db = new DB_Connect();
        $this->db->connect();
    }

    public function getUser($uid, $password) {
        $result = mysql_query("SELECT * FROM users WHERE id = '$uid' AND pswd = '$password'") or die(mysql_error());

        $no_of_rows = mysql_num_rows($result);

        if ($no_of_rows > 0) {

            $result = mysql_fetch_array($result);
            return $result;    

        } else {

            return false;
        }
    }
}

?>

to this and i don’t get the same result..

<?php

class DB_Functions {

    private $db;

    function __construct() {

        require_once 'db_connect.php';

        $this->db = new DB_Connect();
        $this->db->connect();
    }

    public function getUser($uid, $password) {
        $sql = $db->prepare("SELECT * FROM users WHERE id=:id AND pswd=:password");
        $result = $db->query($sql);
        $no_of_rows = mysql_num_rows($result);

        if ($no_of_rows > 0) {

            $result = mysql_fetch_array($result);
            return $result;    

        } else {

            return false;
        }
    }
}
?>
  • 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-10T01:15:04+00:00Added an answer on June 10, 2026 at 1:15 am

    You can’t mix mysql with mysqli or PDO. You need to look at your error logs because this should not be possible – you should be seeing tons of fatal errors.

    public function getUser($uid, $password) {
        $stmt = $db->prepare("SELECT * FROM users WHERE id=? AND pswd=?");
        $stmt->execute(array($uid, $password));
        return $stmt->fetch();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry another newbie query :| To build upon the suggestion which was given here,
Another newbie question: What's the best way to store data in a Cocoa application
I am a newbie to SQL. please help with this. I have the below
Newbie here. I am trying to store the result of my search onto a
I've got another newbie question. I've written a piece of code that converts a
Please excuse the newbie code, im new. Any coding tips are much appreciated as
I am new in Java so it will be a newbie question, here it
SQL Newbie here, and I'm having a hell of a time finding what should
Complete Haskell newbie here, my apologies.... I am trying to create a sequence of
Newbie to C# here.... I have the following code: var xdoc = XDocument.Parse(xml); var

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.