Jump to content

addslashes


Destramic

Recommended Posts

im having problems with my forms. every time i enter the input eg. "o'really" it will return as "o\'really" i have setup my so that it shouldnt happen..here is my file...can anyone help?

.htaccess
[code]
php_value magic_quotes_sybase off
php_value magic_quotes_gpc off
php_value magic_quotes_runtime off
[/code]
Link to comment
Share on other sites

it will always return it with the slashes. This makes things much simpler to insert into tables and to display. Just strip the slashes before you display it

[code]<?php
$string = 'O\'rielly';
echo stripslashes($string); //outputs O'rielly
?>[/code]

Ray
Link to comment
Share on other sites

I recommend to use this function before entering data into the database. It's because [url=http://www.php.net/manual/en/function.mysql-real-escape-string.php]mysql_real_escape_string()[/url] does a better job compared to magic_quotes.

[code]<?php

function sql_quote($value)
{
if(get_magic_quotes_gpc())
$value = stripslashes($value);
return  mysql_real_escape_string($value);
}

?>[/code]

Orio.
Link to comment
Share on other sites

that is correct. magic_quotes_gpc is on by default so no need to do anything. It will be inserted into the database properly. But when you want to display something from the database you will need to stripslashes because php will put the slashes in when displaying fields from the database.

Ray
Link to comment
Share on other sites

thank you...in affect wouldnt using this script be goin back on your self?
striping slashes.
adding slashes (back to square one)?

thanks

[code]
<?php

function sql_quote($value)
{
if(get_magic_quotes_gpc())
$value = stripslashes($value);
return  mysql_real_escape_string($value);
}

?>
[/code]
Link to comment
Share on other sites

But mysql_real_escape_string() escapes more things (\x00, \n, \r, \, ', " and \x1a) than addslashes() (', ", \x00). And magic_quotes has the same affect as addslashes().
See [url=http://shiflett.org/archive/184]here[/url] for more info...

Orio.
Link to comment
Share on other sites

Nor addslashes or mysql_real_escape_string inserts the slash to the table, it's only added to let the escaped value into the db. So stripslashes is not nessesary to output when fetching value from the db, the slash isn't there anyhow.

Manual: http://no.php.net/manual/en/function.addslashes.php
[quote]
to insert the name O'reilly into a database, you will need to escape it. Most databases do this with a \ which would mean O\'reilly. This would only be to get the data into the database, the extra \ will not be inserted.
[/quote]
Link to comment
Share on other sites

Well my version of php and mysql returns the values from the database with the slashes. Even though it is not in the database with slashes, when I echo out the value in php it has the slash. Maybe different for different versions.

Ray
Link to comment
Share on other sites

thanks all for your replies...ive found something strange...ive used this function to add slashes before data is added to the database..it does the $_POST array and returns it with slashes as required..but when i call $_POST['name'] it will display with no slash...very wierd? it should have a slash infront of the single quote..

can anyone explain? thanks

[code]

function add_slashes($value)
{
// Check if string exists
if (is_string($value))
{
return addslashes($value);
}
elseif (is_array($value))
{
return array_map('add_slashes', $value);
}
}

//Add slashes
add_slashes($_POST);

print_r(add_slashes($_POST));
echo $_POST['name'];

Array
(
    [name] => o\'really
    [email] => destramic@hotmail.com
    [error_type] => Broken Link
    [reason_occurred] => test
)
o'really
[/code]
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.