Jump to content

Recommended Posts

I"m having a bizarre issue, and not sure what's going on, I have a form, I fill out the form, and the data gets saved, but whenever I put an apostrophe in my form (i.e. this is what's going on) (notice the "what's") I get an error back saying that I have an error in my mysql syntax at line whatever.

 

I've tried this with two types, the first a varchar and the second a longtext and every time, if I have an apostrophe in there, I get the error, does anyone know what might cause this?

Link to comment
https://forums.phpfreaks.com/topic/192968-apostrophe-not-getting-saved-in-mysql/
Share on other sites

Let me preface this by saying that I am just getting started learning php and MySql, so someone may say this is incorrect. That said I think you need to put in the addslashes function to prevent this problem from happening.

 

you probably have something like this

$lastname=$_POST['lastname'];

and need

$lastname=addslashes ($_POST['lastname']);

this should help but without seeing your code I don't know for sure.

 

The reason this problem occurs is because you have a quote inside of a quoted value the addslashes function fixes this for you.

 

Hope this helps.

hey, thanks for the recommendation. For me, what worked was throwing a foreach that I found in the php.net manual

  //This stops SQL Injection in POST vars 
  foreach ($_POST as $key => $value) { 
    $_POST[$key] = mysql_real_escape_string($value); 
  } 

  //This stops SQL Injection in GET vars 
  foreach ($_GET as $key => $value) { 
    $_GET[$key] = mysql_real_escape_string($value); 
  } 

 

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.