I cannot seem to figure out whats wrong with the code... every time I try and run my script on localhost I get the following error:

Parse > error: syntax error, unexpected T_VARIABLE,expecting ',' or ';' on line 35

Here is my code:

<?php

function fetch_users(){

    $result = mysql_query('SELECT `user_id` AS `id`, `user_username` AS `username` FROM `users`');

    $users = array();

    while (($row = mysql_fetch_assoc($result)) !== false){
        $users[] = $row;
    }

    return $users;
}

//fetch users information
function fetch_user_info($uid){
    $uid = (int)$uid;


    $sql = "SELECT
                `user_username` AS `username`,
                `user_firstname` AS `firstname`,
                `user_lastname` AS `lastname`,
                `user_email` AS `email`,
                `user_about` AS `about`,
                `user_location` AS `location`,
                `user_gender` AS `gender`'
            FROM `users`
            WHERE `user_id` = {$uid}";

    // see what the error is
    echo mysql_error()  

    $result = mysql_query($sql);            

    return mysql_fetch_assoc($result);


}
?>
link|improve this question
You are missing a semicolon the line before: echo mysql_error() – knittl Feb 13 at 16:30
8  
Do you really need to ask questions about parse errors at SO? What happened to good old trying to fix it yourself? – N.B. Feb 13 at 16:31
This page might help you in the future. It's a list of all of the tokens that the PHP parser uses. So for example, when you see unexpected T_VARIABLE, the parser is usually trying to say that you forgot a semi-colon and that it ran into a variable where it would have expected a semi-colon. @nickb already has the right answer, but this advice might help you more generally. – itsmequinn Feb 13 at 16:32
As already mentioned, you're missing a semicolon. Also, your call to mysql_error() should be after the call to mysql_query(), otherwise it's useless. That said, PHP parse errors are usually the easiest bugs to track down -- especially since the error message tells you where to look. Get into the habit of looking closely at the code around the source of an error message so that you don't have to post all of your simple typos here for everyone else to point them out. – Justin ᚅᚔᚈᚄᚒᚔ Feb 13 at 16:33
The problem with this question is: wall of code and an error message at a specific line and we have to guess which line that is in your wall of code. Next time at least highlight where the error is happening. Thanks. – Kev Feb 14 at 23:54
feedback

closed as not a real question by knittl, Johan, bažmegakapa, Kev Feb 14 at 23:52

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

1 Answer

You're missing a semicolon:

echo mysql_error(); // <-- Here
link|improve this answer
Oh sorry... yes this gives me another error as it displays it using (mysql_error) : mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in (this file) on line 37 – Tom Duffy Feb 13 at 16:33
This is likely caused by your SQL statement failing. – nickb Feb 13 at 16:35
The variable's match up with my database for sure, and the database is connecting successfully, could it be the version of PHP/MySQL im using? – Tom Duffy Feb 13 at 16:38
Probably not - Put the echo mysql_error(); AFTER the call to $result = mysql_query($sql); so you see the actual error and why the query is failing. – nickb Feb 13 at 16:39
I did as you said, It now displays this error along with the error i commented to you first: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' FROM users WHERE user_id = 1' at line 8 – Tom Duffy Feb 13 at 16:41
show 3 more comments
feedback

Not the answer you're looking for? Browse other questions tagged or ask your own question.