Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Having Problems With PHP Update : Error?

First the error that I am getting :

"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 'option=2, emp_id=116702 WHERE id = 1' at line 1"

Second the code :

$emp = $_POST['emp'. $x];

$group = $_POST['group' .$x];

mysql_select_db($database_MINE_MySQL_Database, $MINE_MySQL_Database);

$rage = "UPDATE memorial_day SET option=$group, emp_id=$emp WHERE id = $x";

$result2 = mysql_query($rage, $MINE_MySQL_Database) or die(mysql_error());

Well as you see, the $x is a variable is one that changes.. it is anywhere from 1 to 30. And everything in my database is fine.. I see the name as memorial_day, I have check the columns names everything is good.

Now, what i have is a list of 30 slots of employee names and 3 option buttons. The select returns the emp id and the button option returns 1 2 or 3. I have a submit button that does a PHP self and I have an IF ISSET['submit'] that does work and I have checked with a echo statement.

full code ::

IF (isset($_POST['submit'])) {

FOR ($x = 1; $x <= 30; $x += 1 ) {

IF ($_POST['emp'. $x] == '' && $_POST['group' .$x] != '') {

ECHO "One or more Employee is missing.";

break;

} ELSEIF ($_POST['emp'. $x] != '' && $_POST['group' .$x] == '') {

ECHO "One or more Option is missing.";

break;

} ELSEIF ($_POST['emp'. $x] == '' && $_POST['group' .$x] == '') {

} ELSE {

}

$emp = $_POST['emp'. $x];

$group = $_POST['group' .$x];

mysql_select_db($database_MINE_MySQL_Database, $MINE_MySQL_Database);

$rage = "UPDATE memorial_day SET option=$group, emp_id=$emp WHERE id = $x";

$result2 = mysql_query($rage, $MINE_MySQL_Database) or die(mysql_error());

}

}

Update:

I have also tried moving the code inside the ELSE where it should go, but it still dosnt work.. I just want to know why its so frustrating!

Update 2:

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 ''memorial_day' SET 'option'=2, 'emp_id'=116702 WHERE 'id' = 1' at line 1

I put in the single quotes, and I am still having issues, I do think that was one of the issues though.

Update 3:

`id` int(11) NOT NULL auto_increment,

`emp_id` int(10) NOT NULL,

`1_option` int(1) NOT NULL,

That is my Database, I have now changed the option to 1_option.

2 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    In your MySQL statement there is "option" column that in the same time MySQL command.

    So, in cases like your one in the future to avoid such problems always put name of fields inside the `` quotes:

    $rage = "UPDATE `memorial_day` SET `option`=$group, `emp_id`=$emp WHERE `id` = $x";

  • bhima
    Lv 4
    5 years ago

    It appears just like the importance of $nov has an invalid individual in it. Check what it comprises. Check the opposite values as good. What I did is create a role known as MakeMySQLSafe that escapes the strings going into MySQL. It could be a nice inspiration besides to hinder MySQL injection assaults, which can also be VERY severe.

Still have questions? Get your answers by asking now.