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!
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.
Comments