So i have here a function that i created. It worked when i used a postgres database but once i switched over to mysqli, for some reason, it doesn't return the id. Here is my function:
function getAccID($connection, $username){
$res = mysqli_query($connection, "SELECT accounts_id FROM people WHERE people.username ='$username'");
if ($res){
$row = mysqli_fetch_assoc($res);
if ($row){
return ($row[0]);
}
}else{
//handle the error
}
}
And here is how i declare the function:
$accountID = getAccID($connection, $user);
$p->addContent("Account ID: $accountID");
if (!$accountID) $p->addContent('Error: ' . mysqli_error($connection) . "<br>");
PS: If anyone says anything about me using mysqli_query instead of prepare statements, i will murder some babies :L. I'm using it to test, and once everything works, it's easy to switch to prepared statements.
FIXED
Problem with this was with Postgres i could use the id of the fields, but with mysqli, i have to use the name.
Therefore this will not work
$row[0];
It'll have to be:
$row["name_of_field"];
mysqli_fetch_associs what you think it is - i.e. that there are results and that you're returning the desired value within said row (I see a suspicious-lookingif, not a traditionalwhile, and no$row["accounts_id"]). As it is now, either-or could be "failing" which would result in an unexpected result - mainly, no useful return value - due to incomplete execution flow pathing.