Parse Error?

+4 Brandon Bennett · November 5, 2014
I'm having some trouble and i'm not sure what a parse error is. 

I keep getting this error: 

"Parse error: syntax error, unexpected 'return' (T_RETURN) in /functions/users.php on line 14" and I'm not sure what i'm missing.

Here is the code i'm using:

function user_data($user_id){ 
$data = array();


function logged_in() {
return (isset($_SESSION['user_id'])) ? true : false;

function user_exists() {
$username = sanitize($username);
$query = mysql_query("SELECT COUNT ('user_id') FROM `users` WHERE `username` = '$username'")
return (mysql_result($query, 0) ==1) ? true : false;

function user_active() {
$username = sanitize($username);
$query = mysql_query("SELECT COUNT ('user_id') FROM `users` WHERE `username` = '$username' AND `active` = 1")
return (mysql_result($query, 0) ===1) ? true : false;

function user_id_from_username($username) {
$username = sanitize($username);
return mysql_result(mysql_query("SELECT `user_id` FROM `users` WHERE `username` = '$username'"), 0 'user_id');

function login($username, $password) {
$user_id = user_id_from_username($username);

$username = sanitize($username);
$password = md5($password);

return (mysql_result(mysql_query("SELECT COUNT('user_id') FROM `users` WHERE `username` = '$username' AND `password` = '$password'"), 0) ==1) ? $user_id : false;

Please let me know if there is anything that i can do to fix this. 

Thank you!

Post a Reply


- page 1
Oldest  Newest  Rating
0 Teslim Salako · October 19, 2015
paste your code so we can see whats wrong
0 OLayemii Garuba · October 19, 2015
gotten a solution yet?
0 Ayodele Joseph · October 6, 2015
Hello guyz.... I have the same similar problem but have corrected it using this corrections seen here. The problem am having now is that my $data is not submitted to the my database......Plz, i need way forward.
0 Ron Butcher · November 23, 2014
you can include the connect.php file with an include or require statement. That would have all of your $link information.
require 'connect.php';  

$link = mysqli_connect("host", "login_name", "login_password", "database");

The only real catch is that when you include this file at the top of your PHP page, you will not be able to use the $link variable in your functions without adding this line of code in each function that needs to run a query:
function example()
global $link; // This allows a variable that was defined outside the function
// Rest of function code i.e. $query = mysqli_query($link, "SELECT * FROM myTable");

On your error, it looks like you are mixing mysql and mysqli.  The mysql_query only expects a string that is the actual query, the mysqli_query expects two paramaters.  The first is the connect information, the second is the query.
Make sure that your query statement is as follows:
$query = mysqli_query($link, $qryString);  //  Do not forget the 'i' in mysqli
0 Brandon Bennett · November 22, 2014
And what does this mean? i did the edits and got this

"Warning: mysql_query() expects parameter 1 to be string, resource given in /core/functions/users.php on line 13"
0 Brandon Bennett · November 22, 2014
what do i do if i have a separate "connect.php"?
0 Ron Butcher · November 20, 2014
He does need to check the $_POST array to see if it is empty.  If it is empty, and he tries to set $username to a POST variable that does not exist, the page will crash.  He could also put an else statement after checking the POST array to show the log in form if POST is empty.
-1 Code Demon · November 20, 2014
Why do you need to check if the whole $_POST array is empty

if (empty($_POST) === false) {

Isn't the following code enough?
if (empty($username) === true || empty($password) === true) {

Anyway, my take on this that the $errors array is empty. That is why it doesn't display anything.
Also, make sure that the username and password is really posted.
One more thing stay away from mysql functions use mysqli instead.
0 Ron Butcher · November 19, 2014
mysqli needs your connect information passed as well as the query.

$link = mysqli_connect("host", "login_name", "login_password", "database");
$query = mysqli_query($link, "SELECT COUNT(user_id) FROM `users` WHERE `username`='$username'") or die(mysqli_error($link));

I like using the OOP mysqli myself
$mysqli = new mysqli("host", "login_name", login_passord", "database");
$query = $mysqli->query("SELECT COUNT(user_id) FROM `users` WHERE `username` = '$username'") or die($mysqli->error);
0 Brandon Bennett · November 19, 2014
function user_exists($username) {
$username = sanitize($username);
$query = mysqli_query("SELECT COUNT(user_id) FROM `users` WHERE `username` = '$username'") or die(mysql_error());
return (mysqli_result($query, 0) ==1) ? true : false;

Thats the bit in question apparently, more specifically: 

$query = mysqli_query("SELECT COUNT(user_id) FROM `users` WHERE `username` = '$username'") or die(mysql_error());



Server-side, HTML embedded scripting language used to create dynamic Web pages.