MosX Posted July 15, 2003 Share Posted July 15, 2003 I\'m trying to send a MySQL query to my database, but it never works. No matter how many times I try, and no matter what I do, the error doesn\'t go away. First, the query looked like this: $sql = mysql_query(\"INSERT INTO users SET id=\'$this->id\', name=\'$this->name\', title=\'$this->title\', points=\'$this->points\', respect=\'$this->respect\', \" . \"postcount=\'$this->postcount\', artcount=\'$this->artcount\', mood=\'$this->mood\', status=\'$this->status\', pageviews=\'$this->pageviews\', group=\'$this->group\', fullname=\'$this->fullname\', location=\'$this->location\', \" . \"email=\'$this->email\', signature=\'$this->signature\', textoptions=\'$this->textoptions\', logintime=\'$this->logintime\', \" . \"clist=\'$this->clist\', ignorelist=\'$this->ignorelist\', about=\'$this->about\', avatar=\'$this->avatar\', interests=\'$this->interests\', aim=\'$this->aim\', \" . \"msn=\'$this->msn\', yahoo=\'$this->yahoo\', jmonth=\'$this->jmonth\', jday=\'$this->jday\', jyear=\'$this->jyear\', bmonth=\'$this->bmonth\', \" . \"bday=\'$this->bday\', byear=\'$this->byear\', hostaddress=\'$this->hostaddress\', password=\'$this->password\'\") or die(\"Invalid query: \" . mysql_error()); But I kept getting this error: Invalid query: You have an error in your SQL syntax near \'group=\'0\', fullname=\'Dwayne\', location=\'Piscataway, NJ\', email=\'vgamer152\' at line 1 Then when I tried doing it in the \"mysql_query(\"INSERT INTO users (fields) VALUES(values)\");\" format, I got this error: nvalid query: You have an error in your SQL syntax near \'id, name, title, points, respect, postcount, artcount, mood, status, pageviews, \' at line 1 I would really appreciate it if someone could help me. Quote Link to comment Share on other sites More sharing options...
BK87 Posted July 15, 2003 Share Posted July 15, 2003 try [php:1:ad8da68d88] $sql = mysql_query(\"INSERT INTO users SET id=\'$this->id\', name=\'$this->name\', title=\'$this->title\', points=\'$this->points\', respect=\'$this->respect\', postcount=\'$this->postcount\', artcount=\'$this->artcount\', mood=\'$this->mood\', status=\'$this->status\', pageviews=\'$this->pageviews\', group=\'$this->group\', fullname=\'$this->fullname\', location=\'$this->location\', email=\'$this->email\', signature=\'$this->signature\', textoptions=\'$this->textoptions\', logintime=\'$this->logintime\', clist=\'$this->clist\', ignorelist=\'$this->ignorelist\', about=\'$this->about\', avatar=\'$this->avatar\', interests=\'$this->interests\', aim=\'$this->aim\', msn=\'$this->msn\', yahoo=\'$this->yahoo\', jmonth=\'$this->jmonth\', jday=\'$this->jday\', jyear=\'$this->jyear\', bmonth=\'$this->bmonth\', bday=\'$this->bday\', byear=\'$this->byear\', hostaddress=\'$this->hostaddress\', password=\'$this->password\'\") or die(\"Invalid query: \" . mysql_error()); [/php:1:ad8da68d88] Make sure the fields exist in the table. Quote Link to comment Share on other sites More sharing options...
MosX Posted July 15, 2003 Author Share Posted July 15, 2003 I did what you said and got the same exact error. Then I decided to redo my whole table. I dropped it and put the values in all over again. Perfectly. And I\'m still getting the same error. Quote Link to comment Share on other sites More sharing options...
shivabharat Posted July 16, 2003 Share Posted July 16, 2003 Can you show us a sample data which you are trying to insert ? and also a bit of ur tabel structure! Quote Link to comment Share on other sites More sharing options...
MosX Posted July 16, 2003 Author Share Posted July 16, 2003 Ok, here is the sample data. INSERT INTO users SET id=\'1\', name=\'Dwayne\', title=\'New User\', points=\'0\', respect=\'60\', postcount=\'0\', artcount=\'0\', mood=\'Frustrated\', status=\'Normal\', pageviews=\'0\', group=\'0\', fullname=\'Dwayne *****\', location=\'Piscataway, NJ\', email=\'vgamer1525@yahoo.com\', signature=\'I don\'t have one yet.\', textoptions=\'\', logintime=\'1058395904\', clist=\'\', ignorelist=\'\', about=\'Nothing.\', avatar=\'\', interests=\'Web Design, Videogames\', aim=\'TheFramework\', msn=\'\', yahoo=\'vgamer1525\', jmonth=\'7\', jday=\'16\', jyear=\'2003\', bmonth=\'12\', bday=\'13\', byear=\'1985\', hostaddress=\'*******.dyn.optonline.net\', password=\'**********\' The stars are what I just edited now before posting. And here\'s a screenshot of the table structure. http://www.insidephs.com/extra/screenshot.jpg Quote Link to comment Share on other sites More sharing options...
MosX Posted July 17, 2003 Author Share Posted July 17, 2003 By the way, I got the sample data by just changing the MySQL query to an echo statement. Quote Link to comment Share on other sites More sharing options...
shivabharat Posted July 17, 2003 Share Posted July 17, 2003 I really dont see any error :? I am not sure whats causing the error! Try to execute the insert quesry speartely in the mysql prompt and see is you still get the same error? Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 17, 2003 Share Posted July 17, 2003 it seems to me your insert syntax is wrong. try this: INSERT INTO users(columnname1, columnname2) VALUES(\'$field1\', \'$field2\') lemme know if it works Quote Link to comment Share on other sites More sharing options...
MosX Posted July 17, 2003 Author Share Posted July 17, 2003 I got it to work by leaving off the first part of the query after users, and just entering the values. But now I need to know how to skip a value without overwriting it, now that I can\'t specify which values I\'m updating. Quote Link to comment Share on other sites More sharing options...
shivabharat Posted July 17, 2003 Share Posted July 17, 2003 There is nothing wrong with the query INSERT INTO users(columnname1, columnname2) VALUES(\'$field1\', \'$field2\') Even this work INSERT INTO users SE T couluname1=\'$field1\',coulmnname2= \'$field2\' Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.