100 Web Space

Weird error
Page 1 of 1

Author:  Inkstier [ Mon Jun 18, 2007 12:30 pm ]
Post subject:  Weird error

Error: 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 'group ) values('A', 'A', 'A')' at line 1


Author:  jengri2 [ Mon Jun 18, 2007 1:35 pm ]
Post subject: 

Sounds to me like your command was incorrect, but no one can really give you any advice unless you give us the command that you were trying to use.

If you need to replace values with value, that's fine, but sometimes it's as simple as a missing quote or parenthesis.

Author:  Inkstier [ Mon Jun 18, 2007 8:43 pm ]
Post subject: 

I'll post the code, most of it is from a guide I was using because it's been a really long time since I've messed with php and I've forgotten most of it but here's the code.

if ( isset( $title ) && isset( $size ) && isset( $group ) )
// check user input here!
$dberror = "";
$ret = add_to_database( $title, $size, $group, $dberror );
if ( ! $ret )
print "Error: $dberror<BR>";
print "Thank you very much";
else {

function add_to_database( $title, $size, $group, &$dberror )
$user = "nicpow1_collect";
$pass = "********";
$db = "nicpow1_collect";
$link = mysql_pconnect( "mysql1.100ws.com", $user, $pass );
if ( ! $link )
$dberror = "Couldn't connect to MySQL server";
return false;
if ( ! mysql_select_db( $db, $link ) )
$dberror = mysql_error();
return false;
$query = "INSERT INTO soccer ( title, size, group ) values('$title', '$size', '$group')";
if ( ! mysql_query( $query, $link ) )
$dberror = mysql_error();
return false;
return true;

function write_form()
global $PHP_SELF;
print "<form action=\"$PHP_SELF\" method=\"POST\">\n";
print "<input type=\"text\" name=\"title\"> ";
print "Title<p>\n";
print "<input TYPE=\"text\" name=\"size\"> ";
print "Size<p>\n";
print "<select name=\"group\">\n";
print "\t<option value=\"A\"> Group A\n";
print "\t<option value=\"B\"> Group B\n";
print "</select>\n";
print "<input type=\"submit\" value=\"submit!\">\n</form>\n";

Author:  jengri2 [ Mon Jun 18, 2007 10:11 pm ]
Post subject: 

The only thing I can see that I'm unsure about (I'm kind of a noob, but I thought I'd see if I could find something that jumped out at me) is this:

function add_to_database( $title, $size, $group, &$dberror )

Should there be a & there?

Also, is it possible that the values of your variables already have quotes around them so you're in fact adding double quotes?

Sorry I'm not much help. Maybe some day.

Author:  Inkstier [ Mon Jun 18, 2007 10:35 pm ]
Post subject: 

I tried removing the & and all that did was make it say the word "Error" only when I tried to submit data. Then I tried removing the quotes on the values and I get the same error as before with the wrong syntax or whatever.

Author:  Inkstier [ Tue Jun 19, 2007 7:01 pm ]
Post subject: 

Issue has been resolved. Turns out the word "group" is a reserved word in MySQL so it interfered with my code. Got it fixed, thanks anyway for the help.

Author:  jengri2 [ Tue Jun 19, 2007 7:29 pm ]
Post subject: 

Sorry I couldn't help, but thanks for posting the resolution so that I can keep that in mind next time. :)

Author:  Inkstier [ Wed Jun 20, 2007 7:43 am ]
Post subject: 

Np Jengri, thanks for trying. And thanks for the info Psychotic, will come in handy in the future.

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group