Jump to content


Photo

MySQL INSERT query


  • Please log in to reply
9 replies to this topic

#1 MosX

MosX
  • New Members
  • Pip
  • Newbie
  • 5 posts
  • LocationPiscataway, NJ

Posted 15 July 2003 - 02:21 PM

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.

#2 BK87

BK87
  • Members
  • PipPipPip
  • Advanced Member
  • 147 posts
  • LocationPhiladelphia, PA

Posted 15 July 2003 - 02:29 PM

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.

#3 MosX

MosX
  • New Members
  • Pip
  • Newbie
  • 5 posts
  • LocationPiscataway, NJ

Posted 15 July 2003 - 09:16 PM

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.

#4 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 16 July 2003 - 11:39 AM

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

and also a bit of ur tabel structure!
Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#5 MosX

MosX
  • New Members
  • Pip
  • Newbie
  • 5 posts
  • LocationPiscataway, NJ

Posted 16 July 2003 - 11:08 PM

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.../screenshot.jpg

#6 MosX

MosX
  • New Members
  • Pip
  • Newbie
  • 5 posts
  • LocationPiscataway, NJ

Posted 17 July 2003 - 02:05 AM

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

#7 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 17 July 2003 - 07:06 AM

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?
Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#8 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 17 July 2003 - 07:08 AM

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

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

lemme know if it works

#9 MosX

MosX
  • New Members
  • Pip
  • Newbie
  • 5 posts
  • LocationPiscataway, NJ

Posted 17 July 2003 - 07:21 AM

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.

#10 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 17 July 2003 - 08:00 AM

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

Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users