Jump to content

[SOLVED] my sql error with insert


scarface83

Recommended Posts

how do you insert into a row that already exsists ?

 

i have this table im trying to insert into and empty field on an already exsisting row

 

 

datestamp  abs_value      ID                notes                      viewable  TeamRef 

2007-04-28        0            vtc1kb                                  1            14

2007-04-28        0            vtc2a7                                  1            14

2007-01-01        1            vtc1kb      test                        0              0

 

and want to do the following query

 

$query = "INSERT INTO absence_mgt SET abs_value='1', notes='testing' WHERE datestamp='2007-04-28', ID='vtc2av' "; // inserts the selection from the form into the db
$result = mysql_query($query) or die (mysql_error()); // runs the above query

im getting the following error

 

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 datestamp='2007/04/28', ID='vtc2av' at line 1

 

do i need to use and update statemnet and if so how do i do it ?

 

Thanks

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/49066-solved-my-sql-error-with-insert/
Share on other sites

INSERT = NEW

UPDATE = erm.. well UPDATE and existing one

 

and the WHERE needs to have operators!!

 

what are you trying to do ?

WHERE datestamp='2007-04-28', ID='vtc2av' 

 

this

datestamp='2007-04-28' AND ID='vtc2av'

or

datestamp='2007-04-28' OR ID='vtc2av'

 

what!!!

try this one

<?php
$query = "INSERT INTO absence_mgt (abs_value, notes) VALUES ('1', 'testing') WHERE datestamp='2007-04-28', ID='vtc2av' "; 
$result = mysql_query($query) or die (mysql_error()); // runs the above query
?>

 

an insert query should be "INSERT INTO tbl_name (col1,col2) VALUES(15,col1*2);"

 

edit: madTechie I should have read your post as well  UPDATE or INSERT???

Archived

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

×
×
  • 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.