Jump to content

addslashes


The Little Guy

Recommended Posts

Why doesn't this save the slashes when it puts it into the database but it will print them on the screen?

 

<?php
include 'db.php';
$sql = mysql_query("SELECT * from snippets WHERE id = '1'");
while($row = mysql_fetch_array($sql)){
	$v = addslashes($row['code']);
	mysql_query("UPDATE snippets SET `code` = '$v' WHERE id = '1'")or die(mysql_error());
}
echo 'Done';
?>

Link to comment
https://forums.phpfreaks.com/topic/74359-addslashes/
Share on other sites

What do you mean exactly?  I don't see you trying to print anything to the screen?

 

In any case, the slashes added by addslashes() are stripped out by MySQL.  If you want to actually save the slashes to the database, you'd have to call addslashes() twice; I'm not sure why you'd want to do that though.

Link to comment
https://forums.phpfreaks.com/topic/74359-addslashes/#findComment-375718
Share on other sites

Do you understand what addslashes does? It preserves your input... it's working exactly as its supposed to and it is adding the slashes to preserve the data, the characters are treated as literals and the query won't break.

 

All that being said you should be using mysql_real_escape_string and not addslashes.

Link to comment
https://forums.phpfreaks.com/topic/74359-addslashes/#findComment-375834
Share on other sites

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.