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
https://forums.phpfreaks.com/topic/233106-addslashes-is-adding-3-slashes/
Share on other sites

I don't believe you use any escaping, such as addslashes() (which you wouldn't normally use with MySQL anyhow) or mysql_real_escape_string() with a prepared statement.

Make sure magic_quotes_gpc is off.

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 );
}

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.