Namtip Posted October 14, 2010 Share Posted October 14, 2010 I've echoed all the variables and all the values match up. problem: There is no parse of sql error, but the query does not update the database. $query3 = 'UPDATE ecomm_orders_details SET feedback = "' . mysql_real_escape_string($feed) . '", WHERE order_id = "' . $order_id . '"'; mysql_query($query3, $db) or (mysql_error($db)); header('Refresh: 5; URL=main.php'); Can you guys see why this isn't working? Quote Link to comment https://forums.phpfreaks.com/topic/215838-query-not-updating/ Share on other sites More sharing options...
Pikachu2000 Posted October 14, 2010 Share Posted October 14, 2010 Have you echoed the query to make sure it contains the values you'd expect it to contain? You might change or (mysql_error($db)); to: or die(mysql_error($db)); Quote Link to comment https://forums.phpfreaks.com/topic/215838-query-not-updating/#findComment-1122038 Share on other sites More sharing options...
Namtip Posted October 14, 2010 Author Share Posted October 14, 2010 just tried that, it echoes out what I expect it to. UPDATE ecomm_orders_details SET feedback = "1", WHERE order_id = "1" do I need to set all the column when I update or can it be just 1 column like I've tried to do. Quote Link to comment https://forums.phpfreaks.com/topic/215838-query-not-updating/#findComment-1122039 Share on other sites More sharing options...
Pikachu2000 Posted October 14, 2010 Share Posted October 14, 2010 Now paste that echo result into phpMyAdmin (or mysql command line) and see if it succeeds or fails. Quote Link to comment https://forums.phpfreaks.com/topic/215838-query-not-updating/#findComment-1122040 Share on other sites More sharing options...
Namtip Posted October 14, 2010 Author Share Posted October 14, 2010 since adding or die to the query I get this error messages with the adaptions to the code. $query3 = 'UPDATE ecomm_orders_details SET feedback = "' . mysql_real_escape_string($feed) . '", WHERE order_id = ' . $order_id; mysql_query($query3, $db) or die(mysql_error($db)); I recieve this error: Duplicate entry '1' for key 'PRIMARY' $query3 = 'UPDATE ecomm_orders_details SET feedback = "' . mysql_real_escape_string($feed) . '", WHERE order_id = ' . $order; mysql_query($query3, $db) or die(mysql_error($db)); and I get: 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 order_id = 1' at line 4 Quote Link to comment https://forums.phpfreaks.com/topic/215838-query-not-updating/#findComment-1122041 Share on other sites More sharing options...
Namtip Posted October 14, 2010 Author Share Posted October 14, 2010 I echoed the query into phpmyadmin, and nothing gets updated. The tables columns are shown in the right of the query. nothing is displayed errorwise. Quote Link to comment https://forums.phpfreaks.com/topic/215838-query-not-updating/#findComment-1122043 Share on other sites More sharing options...
Namtip Posted October 14, 2010 Author Share Posted October 14, 2010 $query3 = 'UPDATE ecomm_orders_details SET feedback = "' . mysql_real_escape_string($feed) . '", WHERE order_id = "' . $order . '"'; mysql_query($query3, $db) or die(mysql_error($db)); 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 order_id = "1"' at line 4 I don't understand why it has a problems with where order_id = 1. because thats where I want the query to change the already existing column. Quote Link to comment https://forums.phpfreaks.com/topic/215838-query-not-updating/#findComment-1122045 Share on other sites More sharing options...
Namtip Posted October 14, 2010 Author Share Posted October 14, 2010 I'm tapping out to this one, I can't see straight, and I've been trying to answer it by banging my head against for a while now. Just when I think I'm getting the hang of this.. wa pow! night people. Quote Link to comment https://forums.phpfreaks.com/topic/215838-query-not-updating/#findComment-1122050 Share on other sites More sharing options...
gizmola Posted October 14, 2010 Share Posted October 14, 2010 I don't know what you have for a query at this point, but I can tell you that the original query is invalid. UPDATE ecomm_orders_details SET feedback = "1", WHERE order_id = "1" The comma is invalid. The query should be: UPDATE ecomm_orders_details SET feedback = '1' WHERE order_id = 1 I'm actually not even sure if this is correct because it depends on the datatype of the feedback column. If things are "strings" you put quotes around the values. If they are numbers, then you don't. Regardless, you can't have a comma hanging out there, commas only go in the list of columns or values part of a query. For update queries it would only be in the SET part of the query if you're updating multiple columns. Quote Link to comment https://forums.phpfreaks.com/topic/215838-query-not-updating/#findComment-1122052 Share on other sites More sharing options...
Namtip Posted October 15, 2010 Author Share Posted October 15, 2010 Thanks gizmola, that was a great help. Quote Link to comment https://forums.phpfreaks.com/topic/215838-query-not-updating/#findComment-1122336 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.