Tuesday 30 October 2018

php - Syntax error on return statement




I'm doing this simple website, and I have run into this error:



My function:



function user_exists($username)
{

$username = sanitize($username);
$query = mysqli_query($connect, "SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username'");
return (mysqli_result($query, === 0) 1) ? true : false;
}
?>


My php error log:



PHP Parse error:  

syntax error, unexpected '===' (T_IS_IDENTICAL) in function on line 6


Line 6 is the return line.



I understand what a syntax error means, but I'm quite sure that the '===' is not the problem.


Answer



Edit : I was only talking about the ternary condition and this answer is false because the mysqli_result() function doesn't exist.



I guess you are trying to do this :




return mysqli_result($query) === 0 ? false : true;


And as Marcel Korpel said, use prepared statements to avoid security flaws.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...