SQL query help

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 13
Joined: Mon Mar 31, 2014 1:15 pm

SQL query help

Postby Georgezx9 » Sat Apr 12, 2014 2:24 pm

I have the following code which is giving the following error:

( ! ) Parse error: syntax error, unexpected ';' in C:\wamp\www\process-6.php on line 18 (the select from line)

Its a simple code, Name comes from a posted form field, user-name is the field name in the table.

Clearly simple but not simple enough for me. Any help gratefully appreciated.

Code: Select all

mysql_select_db($database) or die("Error connecting to database: ".mysql_error());
       $username = $_POST['Name'];
   $query = ("SELECT * FROM Users WHERE User-Name = '$username'";
   $result mysql_query($query);

New php-forum User
New php-forum User
Posts: 4
Joined: Wed Apr 09, 2014 1:45 am

Re: SQL query help

Postby webmasterInTraining » Sat Apr 12, 2014 4:36 pm

it looks like you never closed your parentheses...

you have this

$query = ("SELECT * FROM Users WHERE User-Name = '$username'";

but you should close it like this

$query = ("SELECT * FROM Users WHERE User-Name = '$username'");

Plus I am not really sure why you are enclosing it with () anyhow seeing how it is a string. I am still pretty new to sql, but I believe that is the problem.

php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Re: SQL query help

Postby seandisanti » Sat Apr 12, 2014 8:11 pm

also, User-Name is a bad field name. if you're going to do compound words use underscore. Otherwise, you have to quote the names so that it's not interpreted to be user minus name.

Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 6 guests