WHERE statement error

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
afbase
Forum Contributor
Posts: 113
Joined: Tue Aug 15, 2006 1:29 pm
Location: SoCAL!!!!

WHERE statement error

Post by afbase »

i have another mysql question.

Code: Select all

$mysql_tickname_insert="INSERT INTO curldata VALUES ('','','$this->dividend','$this->curass','$this->multiplier','$this->bookval','$this->long_term_debt','$this->liabilities') WHERE ticker='$this->ticker';";
the error that is returned:
Error number: 1064 Message: 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 'WHERE ticker=''' at line 1

I made sure that I inserted '$var' on my php variable in the WHERE part of the statement, however I am still a little lost as to what is wrong with it. Any ideas??? thanks
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

WHERE is used on SELECT, UPDATE and DELETE queries. INSERTS require no where clause. They just insert a new row.
afbase
Forum Contributor
Posts: 113
Joined: Tue Aug 15, 2006 1:29 pm
Location: SoCAL!!!!

sigh

Post by afbase »

so how do I insert my values where I have the primary key store into the database? That primary key is what was I going to use as an identifier as to WHERE I would place my data
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Do you want to UPDATE an existing record?
see http://www.w3schools.com/sql/sql_update.asp
afbase
Forum Contributor
Posts: 113
Joined: Tue Aug 15, 2006 1:29 pm
Location: SoCAL!!!!

yes!!!!

Post by afbase »

YES! UPDATE is what was looking for! thanks, so here is my new php-mysql statement:

Code: Select all

$mysql_tickname_insert="UPDATE curldata SET dividend = '$this->dividend', curass = '$this->curass', multiplier = '$this->multiplier', bookval = '$this->bookval', long_term_debt = '$this->long_term_debt', total_cur_liabilities = '$this->liabilities' WHERE ticker='$this->ticker';";
cheers!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Quick little refresher:
  • SELECT: Gets data from a table (or tables - without a WHERE gets every record in the table)
  • DELETE: Deletes data from the table (without a WHERE it deletes every record in the table)
  • UPDATE: Modifies data that is already in the table (without a WHERE it modifies every record in the table)
  • INSERT: Adds a record into the table
afbase
Forum Contributor
Posts: 113
Joined: Tue Aug 15, 2006 1:29 pm
Location: SoCAL!!!!

Post by afbase »

ok thanks guys problem solved
Post Reply