php - insert into a table, where there already is data -
I have an application where I insert data into a mysql database (and that part works fine). Now I have to put data into a table, where there is already some data. The first part, I But I only give me the database error. Could not add the post! This is my inclusion code: What am I missing? I tried to update but I have to update the correct line, so I'm trying to update where etDate (date) is the same. it is working :) row 1
, row2 row4
, row5
and line 6
.
// Need to connect to load and MySQL database stuff ("config.inc.php"); If (empty ($ _ POST)) {// initial query $ query = "under_etage (lys_u_s, skilt_u_s, door_u_s) Insert the value (: lys_u_s ,: skilt_u_s ,: door_u_s) where etData = '29 .04.2014 '"; // update query $ query_params = array ( ': lys_u_s' = & gt; $ _POST [ 'lys_u_s'], ': skilt_u_s' = & gt; $ _POST [ 'skilt_u_s'], ': door_u_s' = & gt; $ _POST ['Door_u_s']); // execute query {$ stmt = $ db- & gt; Ready ($ query); $ Result = $ stmt-> Execute ($ query_params); } Hold (PDOException $ ex) {// For testing, you can use a die and message // die ("Failed to run the query:" $ Ex-> getMessage ()); // Or just use this one to use this: $ reaction ["success"] = 0; $ Response ["message"] = "Database Error. Could not add post!"; Die (json_encode ($ response)); } $ Response ["success"] = 1; $ Response ["message"] = "post successfully added!"; Echo json_encode ($ response); }
if (! ($ _ POST)) {$ lys_u_s = $ _POST ['lys_u_s']; $ Skilt_u_s = $ _POST ['skilt_u_s']; $ Door_u_s = $ _POST ['door_u_s']; $ Adet = $ _POST ['atad']; $ Query = "UPDATE under_etage set lys_u_s = '$ lys_u_s', skilt_u_s = '$ skilt_u_s', door_u_s = '$ door_u_s' where etDate = '$ etDate'";
change lys_u_s
to : insert query lys_u_s
$ query = "insert under_etage (lys_u_s, skilt_u_s, door_u_s) values (: lys_u_s ,: Skilt_u_s ,: Door_u_s) ";
I think you need to use the update statement
edit
Your update statement incorrectly feeling
update under_etage set lys_u_s =: lys_u_s, skilt_u_s =: skilt_u_s, door_u_s =: door_u_s where etData = '29 .04.2014 '
Comments
Post a Comment