Jump to content

[SOLVED] MySQL choking on string?


Galab Juman

Recommended Posts

I wrote a php script that reads a JSON feed and populates a db with the data. It has been working fine but is now erroring out on a certain entry.

 

I get this 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 '..."

 

Since it has worked for all other entries I assume its an issue with the string itself. I am using "mysql_real_escape_string" on every string before I put into DB. Are there other ways to "clean" a string of unaccepted chars? Especially if I don't know what those chars may be ? ( I am not making the JSON feed)

 

Thanks for any insight!

 

Link to comment
Share on other sites

I did implement those calls just to be safe but I think I may have miss diagnosed the issue. But I have narrowed it down to my update

 

This works

$myquery = "INSERT INTO games (nameid, name, `desc`, time, width, height, cat,instructions, keywords,  active, `type`, authorsite, authorname, updated)

VALUES ('$nameid', '$name', '$desc', UNIX_TIMESTAMP(), '$width', '$height', '$cat','$instructions', '$keywords', 'Yes', 'SWF','$authorsite', '$authorname','$updated')";

$result = mysql_query($myquery) or die(mysql_error());

 

This doesn't:

$myquery = "UPDATE games SET nameid='$nameid', name='$name', `desc`='$desc', time=UNIX_TIMESTAMP(), width='$width', height='$height', cat='$cat',instructions='$instructions', keywords = '$keywords', authorsite='$authorsite', authorname='$authorname', updated='$updated'  WHERE nameid = '$nameid'";

$result = mysql_query($myquery) or die(mysql_error());

 

Any thoughts?

And COULD it have to do with the data itself?

Link to comment
Share on other sites

OK so it looks like it IS because of single quotes (apostrophes) inside a string inside my query

 

So I need to escape these... addslashes() seems to work, as does htmlspecialchars()

 

But how do I restore the formayting upon HTML display of this data?

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.