1

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!

3
  • 1
    write var_dump($stmt) before the call to bind_param and tell us the result Commented Mar 9, 2015 at 14:10
  • the reply i got is: bool(false) Commented Mar 9, 2015 at 17:44
  • That means that the DB failed to initialize the prepared statement. Use your last error message function to see what it says. Commented Mar 10, 2015 at 7:42

2 Answers 2

1

I'm noticing spaces in your markup. I'm not sure this allowed. I've never done it myself so I can't speak with certainty.

Where you have if($stmt -> execute()) maybe you can try it with the spaces closed up,?

if($stmt->execute())
Sign up to request clarification or add additional context in comments.

3 Comments

hmm, this seems hard to track. in the binding, are you certain that each variable being bound is indeed an integer?
Also, you have a few places where the code is echoing the word 'false' so I'd probably change each instance slightly to see where exactly the word is being echoed from
i changed the "false" echo but it still returned bool(false) due to this: $stmt = $conn->prepare("INSERT INTO Info (idd, acre, alertlevel, offperc, deffperc, userlevel, upgradeavail) VALUES (?, ?, ?, ?, ?, ?, ?)"); echo (var_dump($stmt)); $stmt->bind_param("iiiiiii", $idd, $acre, $alertlevel, $offperc, $deffperc, $userlevel, $upgradeavail);
1

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.

1 Comment

Glad you got it working. I didn't know that you had to create a new conn for your purposes. If time allows, I would also try out what your code is doing with PHP PDO.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.