Jump to content

Archived

This topic is now archived and is closed to further replies.

MosX

MySQL INSERT query

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Can you show us a sample data which you are trying to insert ?

 

and also a bit of ur tabel structure!

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

By the way, I got the sample data by just changing the MySQL query to an echo statement.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

it seems to me your insert syntax is wrong. try this:

 

INSERT INTO users(columnname1, columnname2) VALUES(\'$field1\', \'$field2\')

 

lemme know if it works

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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\'

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.