Jump to content

[SOLVED] preg_replace(); and databases


Wolphie

Recommended Posts

Hi, i'm having trouble using the following function. When ever i wish to update fields in my database it automatically escapes the quotes(Which i do not want it to do) - So i've tried using regex to replace the \" with a standalone quote ".

 

Update once:

 

<div id=\"example\">Example</div>

 

 

Update twice:

 

<div id=\\\"example\\\">Example</div>

 

 

The preg_replace(); function isn't working. So i'm not sure if its my code or not. (I also do not know the hex for the backslash key)

 

 

 

			case "validate":
			@include("validate.php");

			$title = $_POST['title'];
			$description = $_POST['description'];
			$keywords = $_POST['keywords'];
			$footer = $_POST['footer'];
			$header = $_POST['header'];

			$sql = sprintf('UPDATE `site_options` SET title = \'%s\', description = \'%s\', keywords = \'%s\', footer = \'%s\', header = \'%s\'', 
    			mysql_real_escape_string($title).preg_replace(\x92\x22/g, '"'),
    			mysql_real_escape_string($description).preg_replace(\x92\x22/g, '"'),
			mysql_real_escape_string($keywords).preg_replace(\x92\x22/g, '"'),
			mysql_real_escape_string($footer).preg_replace(\x92\x22/g, '"'),
			mysql_real_escape_string($header).preg_replace(\x92\x22/g, '"')
			);

			if(mysql_query($sql))
			{
				echo 'Site Information Updated';
			}
			else
			{
				die("Error: " . mysql_error());
			}

		break;

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.