0

Run my Query and i got an error.. my query is written below

$qry = "UPDATE Offer  SET offer_year='$offeryear', " .
"course_code='$coursecode', offer_list='$offerlist', " .
"WHERE offer_id ='$offerid'";

the error i got is

ERROR: Record could not be added
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 'WHERE offer_id ='1'' at line 1

done some changes on my update query i still got an error..

Tukai Nancy
  • 127
  • 1
  • 4
  • 12

3 Answers3

3

If you try to check it one by one, you have extra comma before the WHERE clause

$qry = "UPDATE Offer  SET offer_year='$offeryear', " .
       "course_code='$coursecode', offer_list='$offerlist' ". // remove comma here
       "WHERE offer_id ='$offerid'";

As a sidenote, the query is vulnerable with SQL Injection if the value(s) of the variables came from the outside. Please take a look at the article below to learn how to prevent from it. By using PreparedStatements you can get rid of using single quotes around values.

Community
  • 1
  • 1
John Woo
  • 258,903
  • 69
  • 498
  • 492
2

Update your update query like this

$qry = "UPDATE Offer  
        SET offer_year='$offeryear',
            course_code='$coursecode', 
            offer_list='$offerlist' 
        WHERE offer_id ='$offerid'";

You have put extra comma before WHERE condition

GautamD31
  • 28,552
  • 10
  • 64
  • 85
0

Try this (you had a comma after offerlist):

$qry = "UPDATE Offer  SET offer_year='$offeryear', " .
"course_code='$coursecode', offer_list='$offerlist' " .
"WHERE offer_id ='$offerid'";
Stephan
  • 8,000
  • 3
  • 36
  • 42