Page 1 of 1

WHERE statement error

Posted: Tue Dec 26, 2006 7:24 pm
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

Posted: Tue Dec 26, 2006 7:43 pm
by RobertGonzalez
WHERE is used on SELECT, UPDATE and DELETE queries. INSERTS require no where clause. They just insert a new row.

sigh

Posted: Tue Dec 26, 2006 7:49 pm
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

Posted: Tue Dec 26, 2006 8:12 pm
by volka
Do you want to UPDATE an existing record?
see http://www.w3schools.com/sql/sql_update.asp

yes!!!!

Posted: Tue Dec 26, 2006 8:39 pm
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!

Posted: Wed Dec 27, 2006 10:55 am
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

Posted: Wed Dec 27, 2006 10:37 pm
by afbase
ok thanks guys problem solved