Saturday, June 29, 2019

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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...