Page 1 of 1

can any one solve this sql query problem...

Posted: Wed May 04, 2011 4:55 am
by bluestar
i keep on getting error message:
"Database 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 'NAME, LAST NAME, SEX, DOB, COLLEGE, BRANCH, ADMISSION, PASSOUT) VALUES at line 1"
$this->dblink holds the conn info and database selection..part of which is $this->conn_link
similarly realescapestring function performs stripslash..:)

function insertintodb()
{
$this->dblink();
$table1="member_signup";
$query = 'INSERT INTO '.$table1.'(EMAIL, FIRST NAME, LAST NAME, SEX, DOB, COLLEGE, BRANCH, ADMISSION, PASSOUT) /*problem in this line*/
VALUES("' . $this->realescapestring($_POST['emailid']) . '",
"' . $this->realescapestring($_POST['fname']) . '",
"' . $this->realescapestring($_POST['lname']) . '",
"' . $this->realescapestring($_POST['sex']) . '",
"' . $this->realescapestring($_POST['dob']) . '",
"' . $this->realescapestring($_POST['college']) . '",
"' . $this->realescapestring($_POST['branch']) . '",
"' . $this->realescapestring($_POST['ystart']) .'",
"' . $this->realescapestring($_POST['yend']) . '")';

mysql_query($query,$this->conn_link);
if (mysql_error()) { print "Database ERROR: " . mysql_error(); }
return TRUE;
}

Re: can any one solve this sql query problem...

Posted: Wed May 04, 2011 6:32 am
by eivind
Can a column name have a space in it ("LAST NAME")? Sure it's not LAST_NAME or something? According to the error message that's where it stops.

Re: can any one solve this sql query problem...

Posted: Wed May 04, 2011 6:51 am
by bluestar
yes it is....
i solve this problem after readin ur post....actually mysql wont allow you to use space for column name....dats why i stuck here
i used "LAST_NAME" instead of "LAST NAME" and it worked....btw thx for ur reply... :)

Re: can any one solve this sql query problem...

Posted: Wed May 04, 2011 9:23 am
by mikosiko
bluestar wrote:actually mysql wont allow you to use space for column name
just to clarify... mysql allow columns name with space on it, however is not a good practice, and to reference columns like that properly you must enclose the column name in backtics like `LAST NAME`, the drawback of doing this is that make your code less portable, hence your decision to rename the columns is appropriated

Re: can any one solve this sql query problem...

Posted: Wed May 04, 2011 1:21 pm
by McInfo
mikosiko wrote:your decision to rename the columns is appropriated
You mean "appropriate" (an adjective). "Appropriated" is the past tense of the verb "appropriate" which means to set apart for a particular use*. I was amused by the alternative meaning of your sentence. :)

*The Doubleday Dictionary c.1975

Re: can any one solve this sql query problem...

Posted: Wed May 04, 2011 1:50 pm
by mikosiko
Oops!...... thanks McInfo... good to know that we have an expert spell/grammar reviewer at home :D