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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:32:04+00:00 2026-06-10T03:32:04+00:00

It looks like I have some problem with this code. I need to pass

  • 0

It looks like I have some problem with this code. I need to pass $uid and $password to check the user. I thought I had it correct but it’s still not working and I can’t figure it out. I’m new to programming and your help would be greatly appreciated!

update..

this following function works fine but when I modify it as below, it gives me bunch errors..

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;
    }
}

user_function.php

<?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) {
        $stmt = $db->prepare("SELECT * FROM users WHERE id=? AND pswd=?");
        $stmt->execute(array($uid, $password));
        return $stmt->fetch();
    }

}

?>

index.php

<?php

if (isset($_POST['tag']) && $_POST['tag'] != '') {

    $tag = $_POST['tag'];

    require_once 'include/db_functions.php';
    $db = new DB_Functions();

    $response = array("tag" => $tag, "success" => 0, "error" => 0);

    if ($tag == 'login') {

        // check for user
        $user = $db->getUser($_POST['id'], $_POST['pswd']);

        if ($user != false) {

            $response["success"] = 1;
            $response["user"]["id"] = $user["id"];

            echo json_encode($response);

        } else {

            $response["error"] = 1;
            $response["error_msg"] = "Incorrect email or password!";
            echo json_encode($response);
        }
  • 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-10T03:32:05+00:00Added an answer on June 10, 2026 at 3:32 am

    I don’t think your database connection is in scope; try:

    public function getUser($uid, $password) {
        $stmt = $this->db->prepare("SELECT * FROM users WHERE id=? AND pswd=?");
        $stmt->execute(array($uid, $password));
        return $stmt->fetch();
    }
    

    But see the comments about checking return values and error messages to see what the database is actually returning.

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

Sidebar

Related Questions

So I have some code that looks like this: <asp:BoundField DataField=CreatedOn HeaderText=Created on SortExpression=CreatedOn
I have some code that looks like this: foreach(var obj in collection) { try
I have some code that looks like this: var MyObject = function () {
I have some Objective-C code that looks like this: #define myVar 10 float f
I have some code that looks like: static const std::string and( AND ); This
Updated Problem solved, I have some design problem here. The directory looks like that:
So I have some PHP code that looks like: $message = 'Here is the
If I have some HTML that looks like this: <div id=text> This is some
I have some HTML that looks like this: <div> <div class=value> <a href=# class=clicker>Some
In Android, I have some code to check whether the user has GPS switched

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.