Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how do i add stripslashes to this piece of code in php/mysql application

Posted on 2009-05-06
5
Medium Priority
?
233 Views
Last Modified: 2013-12-12
how do i add the get_magic_quotes_gpc()==1 to the attached code so it will remove the slashes that are in my db.  I was able to do this for another section of the code and it works, but i can't figure out how to add it to the array_push and else statement in the code that is attached.

//$R[$row['R_NUMBER']]['ANSWER'][$row['Q_ID']]=$row['TEXT'];
                $R[$row['R_NUMBER']]['ANSWER'][$row['Q_ID']]= ((get_magic_quotes_gpc()==1)?stripslashes($row['TEXT']):$row['TEXT']);

function getRequest($requestNumber,$answerTable='ANSWER')
{
	global $db;
 
	$sql = "SELECT * FROM " . $answerTable ." WHERE R_NUMBER='".$requestNumber."' ORDER BY Q_ID";
 
	$result = mysql_query($sql,$db) or die("ERROR: " . mysql_error());
 
	while ( $row = mysql_fetch_assoc($result) )
	{
		if (preg_match("/\[\]$/", $row['Q_ID']))	//If there is a [] in the ID, it is an array
		{
			preg_match("/([^\[]+)\[\]/", $row['Q_ID'], $matches);	//Split the ID into the number and the []
			$arrayname = $matches[1];
 
			if (!is_array($answer[$arrayname]))
			{
				$answer[$arrayname]=array();
			}
 
			array_push($answer[$arrayname],preg_replace("/<br>/",$cr,$row['TEXT']));
		} else
		{
			$answer[$row['Q_ID']] = preg_replace("/<br>/",$cr, $row['TEXT']);
		}
	}

Open in new window

0
Comment
Question by:justmelat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 51

Accepted Solution

by:
Steve Bink earned 1500 total points
ID: 24322309
I'm assuming it is $row['TEXT'] you want to strip:
on getRequest($requestNumber,$answerTable='ANSWER')
{
        global $db;
 
        $sql = "SELECT * FROM " . $answerTable ." WHERE R_NUMBER='".$requestNumber."' ORDER BY Q_ID";
 
        $result = mysql_query($sql,$db) or die("ERROR: " . mysql_error());
 
        while ( $row = mysql_fetch_assoc($result) )
        {
                $text_to_add =  ((get_magic_quotes_gpc()==1)?stripslashes($row['TEXT']):$row['TEXT']);
                if (preg_match("/\[\]$/", $row['Q_ID']))        //If there is a [] in the ID, it is an array
                {
                        preg_match("/([^\[]+)\[\]/", $row['Q_ID'], $matches);   //Split the ID into the number and the []
                        $arrayname = $matches[1];
 
                        if (!is_array($answer[$arrayname]))
                        {
                                $answer[$arrayname]=array();
                        }
 
                        array_push($answer[$arrayname],preg_replace("/<br>/",$cr,$text_to_add));
                } else
                {
                        $answer[$row['Q_ID']] = preg_replace("/<br>/",$cr, $text_to_add);
                }
        }

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 24328134
Hmm... Yet another compelling argument for atomic, instead of combined, coding!

;-)

Best to all, ~Ray
0
 
LVL 1

Author Comment

by:justmelat
ID: 24366796
Hi routinet:  i tried your solution, but still get the slashes, that then can't be removed.  the only solution was to remove the addslashes.  i don't know what has gone wrong with the new server upgrade, but it has everything off now.
0
 
LVL 1

Author Closing Comment

by:justmelat
ID: 31578449
just didn't work for my application
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 24366886
>>> tried your solution, but still get the slashes, that then can't be removed

Were you trying to use this to cleanse existing data already in a database?  That's not what addslashes() does.  This function's purpose is to escape data before adding it to a database.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question