Jump to content

Problems with mysql_real_escape_string


lynxus

Recommended Posts

Hi Guys,

Im having issues with mysql_real_escape_string

 

For instance, I understand that it only escapes chars, However they just are not entering the DB..

 

For example.

 

$message = "How much is P&P to the UK?";

$message = mysql_real_escape_string($message);

 

 

However when i insert it into a mysql DB, it only inserts "How much is P"

 

Any ideas how i can get this to work.

I want to have these %^&*%$£"!"@ chars in the DB however i want to avoid injections the best way possible.

 

Any help would be grateful.

Thanks

G

Link to comment
Share on other sites

Heres the entire code:

 

$username=$_SERVER['REMOTE_ADDR']; 
$message = $_GET['message'];
$siteid = $_GET['siteid'];
$owner = $_GET['username'];

// If the user hasnt entered anything just die silently, Stops them from filling screen with empty lines.
if ($message == "") {
die;
}

$error = "0";


$con = mysql_connect("localhost","UNAME","PASSWORD");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("DB", $con);

$siteid = mysql_real_escape_string($siteid);
$username = mysql_real_escape_string($username);
$owner = mysql_real_escape_string($owner);
$message = mysql_real_escape_string($message);


mysql_query("INSERT INTO data (username, message, owner, siteid, dispname)
VALUES ('$username', '$message', '$owner', '$siteid', '$owner')");


mysql_close($con);

Link to comment
Share on other sites

Thanks for your help. I never thought about the GET issue.

 

Ive resolved it by doing this in JS ( before sending data )

message = message.replace("&", "%amp");

message = message.replace("+", "%plus");

 

Then in PHP i have:

$message = str_replace("%amp", "&", $message);

$message = str_replace("%plus", "+", $message);

 

Then i escape the string.

 

 

@ Wildteen.

The form is being sent via Ajax. So im using ajax.open(get,url,true);

 

Ive "hacked it" so it works now.

 

I will eventually change the JS / Ajax to use POST

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.