MySQL Query Syntax problem

In the past, I have had MySQL installed on my PC, made it a server and hosted internal websites on it. I have run queries on the MySQL database, both manually and using a PHP form.

However, I now don’t have that PC, and want to host something for the world to see. I’ve got an account with a host that provides MySQL databases, and I’ve started setting up my site. However, the query syntax I’ve used in the past doesn’t seem to work. Previously, I’ve entered things like:

SELECT (first) AS first, (last) AS last FROM names

However, this remote server tells me there is a problem with my syntax. It doesn’t seem to like me using AS, or the commas, and it certainly doesn’t like the brackets. By entering:

SELECT ‘first’ ‘last’ FROM names

I managed to get something, but not the data I was after. I know this isn’t the forum for detailed MySQL questions, but if someone could just tell me if I have a different type of MySQL that I should look for manuals on, I’ll go and do it. Apparently I’m on MySQL 4.0.26, which according to all the online info I can find, should use the () syntax in my first example.

Does anyone know what I’m up against?


I’m no MySQL expert but I think “first” and “last” are reserved words. Like “first record” and “last record”.

So you might want to try SELECT (first) AS FirstName, (last) AS LastName FROM names, and/or change the names of your fields.

My fault for not actually copying and pasting the actual query I’ve run - that was just an example of the syntax I’ve used, not the actual query. I have in fact changed the reference names, to see if it helped, but it didn’t. This is from my script:

insert into images (filename, title, desc, date, downloads, category, disc) values (’$filename’, ‘$title’, ‘$desc’, now(), 0, ‘$category’, ‘$disc’)

The error returned complains about the first (. I just can’t see the problem. Grrrrrr!

Hmmm I don’t see the problem either, but “date” is also a reserved word…try changing that?

Problems with reserved words in SQL can usually be solved by double-quoting the offending parameter. Give that a shot.

I see that you are using '$" before each variable, assume that you are using PHP. Here’s a PHP-based SQL statement which works for me:

 // Create the SQL statement to add the user to the database.
$sql  = "INSERT INTO user (username, userpassword, useremail, usergender, useraddress)";
$sql .= " VALUES ( \"$userName\", password(\"$userPassword\"), \"$userEmail\", $userGender, \"$userAddress\")";

If I remember correct, you might have to escape the single quote too…