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
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
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
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.