AndrewBramwell
AndrewBramwell

Reputation: 494

Updating database entry using PHP not working for text fields

Im trying to run the following code but it is giving me a strange error..

$result = $db->query("UPDATE `items` 
          SET `item_label`= ".$title.", 
              `item_quantity`=".$quantity.", `item_price`=".$price."
          WHERE `item_id` = ".$_POST['id']);

If i remove the item_label = ".$title.", from the above code it works perfectly and successfully updates the quantity and price of the given row. e.g.

$result = $db->query("UPDATE `items` 
          SET `item_quantity`=".$quantity.",
              `item_price`=".$price." 
         WHERE `item_id` = ".$_POST['id']);

when I run the code containing the item_label section it fails to set the item_label. and it gives the following error message..

Unknown column 'Updated Text' in 'field list'

Now the "Updated Text" is the value of $title.

Im baffled as to how / why it is viewing this content as a column header!?

any ideas as to why this would happen?

Upvotes: 1

Views: 166

Answers (1)

Sachin
Sachin

Reputation: 2765

Since its a String you should give quotes around the $title

I would have done something like below

$result = $db->query("UPDATE items SET item_label = '".$title."', item_quantity=$quantity,item_price=$price WHERE item_id =$_POST['id']");

Upvotes: 1

Related Questions