Jump to content

[SOLVED] Problem with UPDATE statement


patheticsam

Recommended Posts

Hi!

 

I have a form with checkboxes. I want to update an already existing entry in mySQL by adding the values selected from the checkboxes so I made an UPDATE sql command and I can't seem to get it working....

 

Here's the update code :

 

<?php

$con = mysql_connect("localhost","user","pass");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

mysql_select_db("tablename", $con);

 

mysql_query(" UPDATE moving SET 1 = '{$_POST['values1']}', 2 = '{$_POST['values2']}', 3 = '{$_POST['values3']}', 4 = '{$_POST['values4']}'                                                                                                                                                 

WHERE email = '{$_POST['email']}' AND movedate = '{$_POST['movedate']}'") or die(mysql_error());

 

?>

 

 

And here's the error that 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 '1 = 'values1', 2 = 'values2', 3 = 'values3', 4 = 'values4', 5 = '', 6 ' at line 1

 

I've double checked everything and can't find what I'm doing wrong......Anyone can help?

 

 

Thanx!!!!!

 

Link to comment
https://forums.phpfreaks.com/topic/147305-solved-problem-with-update-statement/
Share on other sites

Not sure but if I were you I'd try putting ` around your fields like

 

mysql_query(" UPDATE moving SET `1` = '{$_POST['values1']}', `2` = '{$_POST['values2']}', `3` = '{$_POST['values3']}', `4` = '{$_POST['values4']}'                                                                                                                                                 

WHERE email = '{$_POST['email']}' AND movedate = '{$_POST['movedate']}'") or die(mysql_error());

Archived

This topic is now archived and is closed to further replies.

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