Update Statement Continues to give me an error

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


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-31-2007
jtrainaldi
 
Posts: n/a
Default Update Statement Continues to give me an error


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.

Reply With Quote
  #2 (permalink)  
Old 08-31-2007
Paul Lautman
 
Posts: n/a
Default Re: Update Statement Continues to give me an error

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.


Reply With Quote
  #3 (permalink)  
Old 09-01-2007
Jerry Stuckle
 
Posts: n/a
Default Re: Update Statement Continues to give me an error

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
==================
Reply With Quote
  #4 (permalink)  
Old 09-01-2007
Aaron Saray
 
Posts: n/a
Default Re: Update Statement Continues to give me an error

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

Reply With Quote
  #5 (permalink)  
Old 09-02-2007
Ben Sehara
 
Posts: n/a
Default Re: Update Statement Continues to give me an error

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



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:37 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0