Everything with it is fine. The name of the database and table, the name of the columns etc. $username is good and exists in the database. Yet, after this runs, if I “alert” $dbuid it comes up as 0 and $dbusername comes up as empty. MySQLi throws no errors. (That is why I did if(! .. ) echo error;, to see if it throws an error on anything, but it works perfectly fine.) Where am I going wrong ?
if(!$msmysqli = new mysqli("localhost","root","","ms")){
echo $msmysqli->connect_error;
}
if(!$stmt = $msmysqli->prepare("SELECT id,name,password FROM accounts WHERE name=?")){
echo $msmysqli->error;
}
if(!$stmt->bind_param("s",$username)){
echo $stmt->error;
}
if(!$stmt->execute()){
echo $stmt->error;
}
if(!$stmt->bind_result($dbuid,$dbusername,$dbpassword)){
echo $stmt->error;
}
$stmt->close();
You simply forgt to fetch your result to get the row… thats why your code wasn’t working as expected! Another thing to bare in mind is that an object, at least in php, returns always its instance while being constructed! The statement $msmysqli = new mysqli(…) is never going to be false! thats why you should check your connection as shown!