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?

Link to comment
Share on other sites

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

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.