0

Hi,

I'm pretty new to php and MySQL.
I am trying to use a form to update a the database. However it just doesn't seem to actually work.
I also am getting this error from printing out errors:
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 'INT1 = '', INT2 = '', INT3 = '', INT4 = '' at line 1


Here is my code that I am using to update the database from the form.
All the capital stuff (eg. FF, FPL, FFL) is the name and the id of the <input>'s in the form.

Have I done this correct?

// if form has been submitted, update record
if (array_key_exists('publish', $_POST)) {
	$team = $_GET['team'];
  // prepare update query
	$sql = "UPDATE team SET FF = ?,	FPL = ?, FPR = ?, FFL = ?, CHF = ?, FFR = ?, WL = ?, C = ?, WR = ?, BFL = ?, CHB = ?, BFR = ?, BPL = ?, BPR = ?, FB = ?, RUCK = ?, RR = ?, ROVER = ?, INT1 = ?, INT2 = ?, INT3 = ?, INT4 = ?, INT5 = ?, INT6 = ?, EMG1 = ?, EMG2 = ?, EMG3 = ?, EMG4 = ?, EMG5 = ?, EMG6 = ?, COACH = ?, CAP = ?, VCAP = ? WHERE team = '".$team."'";
  	$update = $conn->prepare($sql);
  // execute query by passing array of variables
  	$done = $update->execute(array($_POST['FF'], $_POST['FPL'], $_POST['FPR'], $_POST['FFL'], $_POST['CHF'], $_POST['FFR'], $_POST['WL'], $_POST['C'], $_POST['WR'], $_POST['BFL'], $_POST['CHB'], $_POST['BFR'], $_POST['BPL'], $_POST['BPR'], $_POST['FB'], $_POST['RUCK'], $_POST['RR'], $_POST['ROVER'], $_POST['INT1'], $_POST['INT2'], $_POST['INT3'], $_POST['INT4'], $_POST['INT5'], $_POST['INT6'], $_POST['EMG1'], $_POST['EMG2'], $_POST['EMG3'], $_POST['EMG4'], $_POST['EMG5'], $_POST['EMG6'], $_POST['COACH'], $_POST['CAP'], $_POST['VCAP']));
	echo "$sql"; //this is here so I can see whats getting sent.
}

Am I supposed to put the $_POST, where the ? are in the sql statement? or put them in a variable then add that in instead of the ? ?

Thanks for your help.

Cheers,

QWaz

2
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by QWaz
0

One problem is that MySQL sees INT1, INT2 ... as a reserved word and it must be escaped by ` , thus this part of your query should look like :

... `INT1` = ?, `INT2` = ?, `INT3` = ?, `INT4` = ?, `INT5` = ?, `INT6` = ? ...

This should fix one error, but you might have more. Good luck.

0

That worked.

WOW, something so simple.

Thanks mate, your a champ.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.