This is a discussion on Update Statement Continues to give me an error within the MySQL Database forums, part of the Database Forums category; MySQL database keeps on giving me the error Error: You have an error in your SQL syntax; check the manual ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
MySQL database keeps on giving me the error Error: 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 '' at line 1. My code looks like this: $sql = "UPDATE news SET news_header = '".$news_header."' WHERE news_id = $n_id"; what is echoed - UPDATE news SET news_header = 'Test' WHERE news_id = 28 any suggestions. I removed the WHERE clause and it worked correctly. |
|
|||
|
jtrainaldi wrote:
> MySQL database keeps on giving me the error > > Error: 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 '' at line 1. > > My code looks like this: > > $sql = "UPDATE news SET news_header = '".$news_header."' WHERE news_id > = $n_id"; > > what is echoed - UPDATE news SET news_header = 'Test' WHERE news_id > = 28 > > any suggestions. I removed the WHERE clause and it worked correctly. Assuming you are using PHP to construct this query, can you try: $sql = " UPDATE news SET news_header = '".$news_header."' WHERE news_id = '$n_id'"; and post the result. |
|
|||
|
jtrainaldi wrote:
> MySQL database keeps on giving me the error > > Error: 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 '' at line 1. > > My code looks like this: > > $sql = "UPDATE news SET news_header = '".$news_header."' WHERE news_id > = $n_id"; > > what is echoed - UPDATE news SET news_header = 'Test' WHERE news_id > = 28 > > any suggestions. I removed the WHERE clause and it worked correctly. > What's your CREATE TABLE look like? -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
On Aug 31, 3:20 pm, jtrainaldi <jtraina...@gmail.com> wrote:
> MySQL database keeps on giving me the error > > Error: 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 '' at line 1. > > My code looks like this: > > $sql = "UPDATE news SET news_header = '".$news_header."' WHERE news_id > = $n_id"; > > what is echoed - UPDATE news SET news_header = 'Test' WHERE news_id > = 28 > > any suggestions. I removed the WHERE clause and it worked correctly. Are you sure thats the exact query that was causing the error? It seems as maybe your news_header variable contained a single quote when running that update - for example: aaron's cool topic. Then you'd end up getting a query like UPDATE news SET news_header = 'aaron's cool topic' where news_id = 28; Then, it would throw it off and create that issue. I would add some filtering to your $news_header variable (mysql_real_escape_string() for example). -aaron |
|
|||
|
Try this.
$sql = "UPDATE news SET news_header = '".$news_header."' WHERE news_id = '".$n_id."'"; Ben "jtrainaldi" <jtrainaldi@gmail.com> wrote in message news:1188591602.072071.222250@y42g2000hsy.googlegr oups.com... > > MySQL database keeps on giving me the error > > Error: 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 '' at line 1. > > My code looks like this: > > $sql = "UPDATE news SET news_header = '".$news_header."' WHERE news_id > = $n_id"; > > what is echoed - UPDATE news SET news_header = 'Test' WHERE news_id > = 28 > > any suggestions. I removed the WHERE clause and it worked correctly. > |