Perad Posted August 25, 2007 Share Posted August 25, 2007 Is there someway I can clean this query to make it work with MySQL, I think it is going wrong because mysql is interpretting the - in the item code as a minus. Query is the following. UPDATE p_MUM - INOPT SET mconnec = 'USB', itemcode = 'MUM-INOPT', item = 'MicroSoft IntelliMouse Optical - PS2/USB', model = 'Microsoft D58-00017', tm = 'Optical', mwireless = 'No', tr = '800dpi', mdocking = 'Yes', mrecharge = '', mbuttons = '5', mscroll = 'Yes', weight = 'PS2, USB 1.1/2.0', price = '0.50', WHERE itemcode = 'MUM-INOPT' Error starts at '-INOPT" so it must be the - character. My PHP is... foreach($_POST as $K => $V) { //may want to clean $K as well if ($K == "submit") { } else { if ($_GET['page'] == "process") { $databaseentry .= $K . "='" . $this->cleanString($V). "', "; } else { $Clean[$K] = $this->cleanString($V); } } } if ($_GET['page'] == "process") { } else { $fields = implode(",",array_keys($Clean)); $Values = implode("','",$Clean); } if ($_GET['page'] == "process") { $sql = "UPDATE p_$cleanpart SET $databaseentry WHERE itemcode='".$_POST['itemcode']."'"; echo $sql; } else { $sql = "INSERT INTO p_$cleanpart ($fields) VALUES ('$Values')"; } $result = mysql_query($sql) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/66660-trouble-with-mysql-query/ Share on other sites More sharing options...
Hypnos Posted August 25, 2007 Share Posted August 25, 2007 UPDATE `p_MUM - INOPT` SET You can use ` style quotes to encase table and field names. You use ' style quotes for values. Since your table has spaces in it's name, it needs to be encased. Also: price = '0.50' You do not need a comma before the WHERE. Quote Link to comment https://forums.phpfreaks.com/topic/66660-trouble-with-mysql-query/#findComment-333990 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.