Jump to content

[SOLVED] Stupid question about mysql_real_escape_string()


JHolovacs

Recommended Posts

I tried searching for this online, but my keywords are just too vague; I'm hoping someone knows this off the top of their head.

 

if I get a $_REQUEST variable in, i filter it thru mysql_real_escape_string as a matter of course; it makes sense to me, the security benefit is clear, but the problem is it tends to malform the data I'm trying to insert into mu MySQL database.  for example:

 

$store_name = mysql_real_escape_string($_REQUEST['store_name']);
$query = "INSERT INTO stores (store_name) VALUES ('$store_name')";
$result = mysql_query($query);

 

All is well if I enter "SpudRuckers" as the form data, but if I enter "Joe's Cheese Eatery" the data in my database shows up as "Joe\'s Cheese Eatery" which is not what I want.

 

What am I doing wrong?

Since you have magic_quotes turned on, you should use stripslashes() before the mysql_real_escape_string():

<?php
$store_name = mysql_real_escape_string(stripslashes($_REQUEST['store_name']));
$query = "INSERT INTO stores (store_name) VALUES ('$store_name')";
$result = mysql_query($query);
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

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