Jump to content

MySQL INSERT query


MosX

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.

Link to comment
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.

Link to comment
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.

Link to comment
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

Link to comment
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.