Jump to content

addslashes is adding 3 slashes?


ask9

Recommended Posts

Hi guys

 

When I insert a data into MySQL and thru addslashes() it is adding not one but 3 slashes in mysql.

 

By the way here are the codes,

<?php
//$conn = new mysqli('localhost', 'root', '', 'my_db');
$conn = new mysqli('localhost', 'coder9_work', '******', 'coder9_portfolio');
$query = "INSERT into portfolio(category, title, description, version, started, finished) VALUES (?, ?, ?, ?, ?, ?)";

$select = $_POST['select'];
$title = addslashes($_POST['title']);
$description = $_POST['description'];
$version = $_POST['version'];
$started = $_POST['started'];
$finished = $_POST['finished'];


$stmt = $conn->stmt_init();
if($stmt->prepare($query)) {
$stmt->bind_param('ssssss', $select, $title, $description, $version, $started, $finished);
$stmt->execute();
}

if($stmt) {
echo "Thank you!";
} else {
echo "There was a problem. Please  try again later.";
}
?>

 

How do I fix this problem so that It will add only one slashes?

 

Thanks in advanced.

Link to comment
Share on other sites

By the way here is the example data that is added in MySQL.

<a href=\\\'selsosa.com\\\'>selosa</a>

 

As you can see I'm trying to insert a HTML tag codes in the database.

But addslashes is adding 3 slashes.

 

 

Thanks in advanced.

Link to comment
Share on other sites

If you can get it turned off, that would be the preferred thing to do. If you have to do it via the .htaccess file: php_value magic_quotes_gpc off. If all else fails, you can test for it in the script, and use its inverse function, stripslashes() on incoming data. This will work as long as $_POST doesn't contain sub-arrays. If you use $_GET, or $_COOKIE data also, those would need to be handled too.

 

if( function_exists(get_magic_quotes_gpc()) && get_magic_quotes_gpc() === TRUE ) {
     array_map( 'stripslashes', $_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.