PHP Fatal error: Call to a member function bind_param() on a non-object (PHP-MySQL PreparedStatement)

JamesAnd

I know this has been asked several times here but I assure you i tried every suggestion but that didn't help me. (I guess because this error is caused by a wide number of factors).

Here is my code:

$stmt = $conn->prepare("INSERT INTO User (Username, Password, Email, Race) VALUES (?, ?, ?, ?)");
        $stmt->bind_param("ssss", $Username, $Password, $Email, $Race);

    if($stmt->execute())
    {
        $stmt = $conn->prepare("SELECT Id FROM User WHERE Username=?");
    if ($stmt === FALSE)
    {
        echo ($this->conn->error);
    }
        $stmt->bind_param("s", $Username);
        if($stmt -> execute())
        {
            $stmt -> bind_result($idd);
            $stmt -> fetch();
            echo $idd;
            $acre=1000;
            $alertlevel=0;
            $offperc=0;
            $deffperc=0;
            $userlevel=1;
            $upgradeavail=0;

            $stmt = $conn->prepare("INSERT INTO Info (idd, acre, alertlevel, offperc, deffperc, userlevel, upgradeavail) VALUES (?, ?, ?, ?, ?, ?, ?)");
            $stmt->bind_param("iiiiiii", $idd, $acre, $alertlevel, $offperc, $deffperc, $userlevel, $upgradeavail);

            if($stmt -> execute())
            {
                echo "";
            }
            else
            {
                echo "false";
            }
        }
        else
        {
            echo "false";
        }
    }
    else
    {
        echo "false";
    }

and that is my SQL table:

Table User: Id*(int and primary)* Username*(varchar)* Password*(varchar)* Email*(varchar)* Age*(int)*

Table Info: IdPrimary*(int and primary)* idd*(int)* acre*(int)* alertlevel*(int)* offperc*(int)* deffperc*(int)* userlevel*(int)* upgradeavail*(int)*

the one giving me the error is located on line 57 which is:

$stmt->bind_param("iiiiiii", $idd, $acre, $alertlevel, $offperc, $deffperc, $userlevel, $upgradeavail);

I used this to make sure that the select prepare is working and indeed it is.

if ($stmt === FALSE)
{
    echo ($this->conn->error);
}

this shows me that indeed it was able to fetch the Id from table User

  echo $idd; 

Sorry for the long article but I wanted to give you all the possible details :) Thanks for the help!

JamesAnd

It turned out you can not use the same $stmt to INSERT into two different table. so what I did is create a new $conn named $connn and it worked. Why its not possible to INSERT into two different tables is beyond me! hope someone sheds light on this.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Fatal error: Call to a member function bind_param() on a non-object in PHP

(PHP) Fatal error: Call to a member function bind_param()

PHP Fatal error: Call to a member function bind_param()

PHP Error: call to a member function bind_param() on a non-object

Fatal error stating "Call to a member function bind_param() on a non-object"

Fatal error: Call to a member function bind_param() on a non-object in on

Fatal error: Call to a member function bind_param() on a non-object

Fatal error: Call to a member function bind_param() on boolean in C:\xampp\htdocs\index.php

Fatal error: Call to a member function bind_param() on boolean in php while inputing String from Android app

Mysql: Call to a member function bind_param() on a non-object

PHP :Fatal error Call to a member function format() on a non-object

Fatal error: Call to a member function query() on a non-object in PHP

PHP Fatal error: Call to a member function GetFolderByType() on a non-object in

PHP Fatal error: Call to a member function prepare() on a non-object

PHP fatal error: Call to a member function asXML() on a non-object

PHP: Fatal error: Call to a member function insert() on a non-object

Error php sql: Call to a member function bind_param() on boolean

Fatal error: Call to a member function fetch_assoc() on a non-object php mysql prepared statement

Fatal error: Call to a member function bind_param() on boolean

Call to a member function bind_param() on a non-object MySQLi

Issue with "Call to a member function bind_param() on a non-object"

Call to a member function bind_param() on a non-object error, but SQL works

<b>Fatal error</b>: Uncaught Error: Call to a member function bind_param() on boolean in E:\Xamp\htdocs\FindMyDoc\Api.php:100

Fatal error: Call to a member function execute() on a non-object in /blah/blah/blah.php

Can't access a global variable in PHP-"Fatal error: Call to a member function query() on a non-object"

PHP Fatal error: Call to a member function format() on a non-object any idea

PHP/MySQLi - Fatal error: Call to a member function mysqli_query() on a non-object

Fatal error: Call to a member function getOwner() on a non-object in my PHP code

Fatal error: Call to a member function getTelephone() on a non-object in Observer.php while payment using payUmoney