Jump to content

[SOLVED] Aargh! - escaping, magic_quotes, slashes, quote marks - I don't understand


Recommended Posts

Hi Folks,

 

What I want to do is very simple but I am falling foul of escaping characters...

 

I have some html/php forms where users update data in the database.  It all works well until someone tries put in a name like Rick o'shea and then one of two things happen...

 

1. On a form that is located in the root directory it goes in OK but when they go back to update the form again the textbox should be populated with the current value from the database but it says Rick o'

2. On a form that is located in a password-protected sub-directory it puts Rick o\'shea in and when they go back to update the form again the textbox should be populated with the current value from the database but it says Rick o\

 

Do I need to do something extra with .htaccess (currently just defines index.php as homepage)? What ? and will it correct the problem for the sub-directory as well as the root?

 

Many Thanks in advance

You have to user mysql_real_escape_string or equivalent to escape strings when sending queries to database.

 

I'm not sure if you have to escape for the folders or not.

 

Also check that in html you are setting html attributes with double quotes and not single quotes.

 

And of course, use a proper subject please

I am using

 

$event1winnerupdate =mysql_real_escape_string($_POST['event1winnerupdate']);

 

to define the variables that I then use in

 

$query1="UPDATE tournamentevents SET

eventwinner='$event1winnerupdate' WHERE....  "

 

is that what you mean or am I missing something...?

 

 

If you use like that, your variable is an escaped variable. If you are using something like:

 

$event1winnerupdate = mysql_real_escape_string($_POST['event1winnerupdate']);

$query1="UPDATE tournamentevents SET
eventwinner='$event1winnerupdate' WHERE....  ";

create_folder($event1winnerupdate);

 

you are sending an escaped string to create folders. What you should do is something like this:

 

$event1winnerupdate = $_POST['event1winnerupdate'];

$query1="UPDATE tournamentevents SET eventwinner='" . mysql_real_escape_string($event1winnerupdate) . "' WHERE....  ";

create_folder($event1winnerupdate);

 

So the folder name you have created is not escaped.

OK - removing the "mysql_real_escape_string" makes it work OK for uploading data.

 

It now populates the box with Rick o    when you go back in to make another update

 

echo "<input type='text' name='event1winnerupdate'  value='$event1data[10]'  size='30' maxlength='40'>";

 

I understand that the problem lies in the use of single quotes as it sees value='rick o'shea' hence thinks that quote mark ends the string but how do I get round this because using double quote value="$event1data[10]" confuses the echo "......

OK I've cracked it by using " in my echo statement and escaping it with \

 

echo "<input type='text' name='event1third1update'  value=\"$event1data[14]\"  size='30' maxlength='40'>";

 

Just a find and replace and away I go - Thanks Guys!!

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.