Jump to content

Trouble with MySQL query


Perad

Recommended Posts

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());	

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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