Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax Error? I can't see it! 2

Status
Not open for further replies.

cyberspace

Technical User
Aug 19, 2005
968
GB
Hi, having an irritating problem with this simple code:

<?php

include("../config.php");

$sql = "INSERT INTO users VALUES ('', '$username', '$password', 'forename', 'surname', 'email', 'local_ip', 'user_type',)";

$result = mysql_query ( $sql ) or die ( mysql_error ( ) );

header ("Location: confirmuseradded.html");

?>

every time i try to submit a new user, i get the message "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 ')' at line 1"

I've tried changing all sorts round there, including removing the include and manually typing the connection/db info...but still the same error!

Can anybody see what i'm missing? PC is near to going out of the window!

Thanks

'When all else fails.......read the manual'
 
Well what do you know...the second I post this i spotted a rogue comma after "user_type" in the insert statement...alas it was nowhere near line 1!

Sorry about that.

'When all else fails.......read the manual'
 
I know this is a little late, but when you just can't seem to find the problem, and the mysql_error comes back with the "Check the manual for the syntax to use near ..."

I suggest you echo out the query you are trying to run. so you see exactly what is going on. echo $sql; That way you can see th exact query that is getting sent to the DB. with all the variables replaced etc...

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I have to endorse vacunita's approach to debugging...
Echo your $sql, even consider pasting it into a mysql command session to see if it's valid and the output matches your expectations.

Labor intensive, yes. Useful to prevent wasting more time, YES!

D.E.R. Management - IT Project Management Consulting
 
Thanks for that tip, very useful indeed!

'When all else fails.......read the manual'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top