can any one solve this sql query problem...

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
bluestar
Forum Newbie
Posts: 13
Joined: Thu Mar 17, 2011 7:19 am

can any one solve this sql query problem...

Post 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;
}
eivind
Forum Commoner
Posts: 28
Joined: Tue Apr 19, 2011 7:57 am

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

Post 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.
bluestar
Forum Newbie
Posts: 13
Joined: Thu Mar 17, 2011 7:19 am

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

Post 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... :)
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

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

Post 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
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

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

Post 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
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

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

Post by mikosiko »

Oops!...... thanks McInfo... good to know that we have an expert spell/grammar reviewer at home :D
Post Reply