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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:16:19+00:00 2026-06-05T08:16:19+00:00

Im getting Fatal error: Call to a member function prepare() on a non-object Error

  • 0

Im getting ” Fatal error: Call to a member function prepare() on a non-object ” Error the script worked fine on my other hosts but now ive moved hosts its showing this error and donno why because the coding is fine.

include 'functions/functions.php';  
global $db;

$db = mysqlconnect();

$password = md5($_POST['mypassword']);

$mod = '1' ;
$statement = $db->prepare("SELECT * FROM users WHERE username = ? AND password = ? And mod = ?");
$statement->execute(array($_POST['myusername'],$password, $mod));

$count = $statement->rowCount();


if($count == 1){
    $db = mysqlconnect();
  // Register $myusername, $mypassword and redirect to file "login_success.php"

$_SESSION['user'] = $_POST['myusername'] ;

//Test if it is a shared client
if (!empty($_SERVER['HTTP_CLIENT_IP'])){
  $ip=$_SERVER['HTTP_CLIENT_IP'];
//Is it a proxy address
}elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
  $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}else{
  $ip=$_SERVER['REMOTE_ADDR'];
}



$sqll = "UPDATE users SET lastip=? WHERE username=?";
    $q = $db->prepare($sqll);
    $q->execute(array($ip,$_SESSION['username']));

$_SESSION['user'] = $_POST['myusername'] ;

$sqlll = "INSERT INTO user_log (username,ip) VALUES (?, ?)";
    $qq = $db->prepare($sqlll);
    $qq->execute(array($_SESSION['username'],$ip));




header("Location: home.php");
} else {
  echo "Wrong Username or Password";
}

Has you can see its saying the prepare is wrong on this line

$statement = $db->prepare("SELECT * FROM users WHERE username = ? AND password = ? And mod = ?");

when there is nothing wrong with the code which i can see….

Here is my function file which inculdes the mysqlconnect

    function mysqlconnect(){
     global $db;
    $host = 'localhost';
    $port = 3306; // This is the default port for MySQL
    $database = '';
    $username = '';
    $password = '';




    // Construct the DSN, or "Data Source Name".  Really, it's just a fancy name
    // for a string that says what type of server we're connecting to, and how
    // to connect to it.  As long as the above is filled out, this line is all
    // you need :)
    $dsn = "mysql:host=$host;port=$port;dbname=$database";

    // Connect!
    $db = new PDO($dsn, $username, $password);

}

I have toke my connect info out just so everyone knows…

  • 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-05T08:16:20+00:00Added an answer on June 5, 2026 at 8:16 am

    When stating $db = mysqlconnect();, you expect mysqlconnect() to return a PDO object. Change the function to this to make it working:

    function mysqlconnect(){
        $host = 'localhost';
        $port = 3306; // This is the default port for MySQL
        $database = '';
        $username = '';
        $password = '';
    
        // Construct the DSN, or "Data Source Name".  Really, it's just a fancy name
        // for a string that says what type of server we're connecting to, and how
        // to connect to it.  As long as the above is filled out, this line is all
        // you need :)
        $dsn = "mysql:host=$host;port=$port;dbname=$database";
    
        // Connect!
        $db = new PDO($dsn, $username, $password);
    
        // Return PDO object
        return $db;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Fatal error: Call to a member function prepare() on a non-object Is what I
I'm getting: Fatal error: Call to a member function setAccessToken() on a non-object in
I'm getting: Fatal error: Call to a member function query() on a non-object in
Error: Fatal error: Call to a member function bind_param() on a non-object in /var/www/web55/web/pdftest/events.php
I am getting this error Fatal error: Call to a member function hasResource() on
Getting the following the error : Fatal error: Call to a member function load()
I am getting an error Fatal error: Call to a member function has() on
I am getting Fatal error: Call to undefined function getSContent() with the included code
With vBulletin in PHP, I'm getting this error Fatal error: Call to a member
I am not sure why but I am getting this error Fatal error: Call

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.