Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4531244
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T13:53:10+00:00 2026-05-21T13:53:10+00:00

Can I loop through DB results and remove Slashes? (I started getting more slashes

  • 0

Can I loop through DB results and remove Slashes?

(I started getting more slashes everytime I edited the text and put it back into the DB)

$db = new connection();

$query = "SELECT * FROM ITEMS, ALPACA_SALES WHERE ITEMS.uid = '$id' AND ALPACA_SALES.uid = ITEMS.uid";
$results = $db->query($query);

$data = array();    
while($info = mysql_fetch_array($results))
{
    $data[] = stripslashes($info);
}

But I am getting the following error:

Notice: Array to string conversion in /home/content/myfile.php  on line 78

When I add the data to the database I do the following:

if (!empty($_POST['more_text']))
{
    $more_text = addslashes($_POST['more_text']); 
}
else
{
    $error = false;
    $error_message = "Please add a description.";
}

And then I use UPDATE for the insert into the DB:

$query2 = "UPDATE ALPACA_SALES SET more_text = '$more_text' WHERE uid = '$id'"; 

$result = $db->query($query2);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T13:53:11+00:00Added an answer on May 21, 2026 at 1:53 pm

    You can’t run stripslashes() on an array, which is what $info is from storing mysql_fetch_array($results). You could iterate through $info and strip slashes on each entry, or explicitly strip slashes if you don’t need to do all of them.

    $i=0;
    while($infoarray = mysql_fetch_assoc($results))
        {
            foreach($infoarray as $field=>$value){
                $data[$i][$field] = stripslashes($value);
            }
            $i++;
        }
    

    Edit: You can also create a small function to strip slashes in an array, as outlined in the documentation here: http://us.php.net/manual/en/function.stripslashes.php

    function stripslashes_deep($value)
    {
        $value = is_array($value) ?
                    array_map('stripslashes_deep', $value) :
                    stripslashes($value);
    
        return $value;
    }
    
    // Example
    $array = array("f\\'oo", "b\\'ar", array("fo\\'o", "b\\'ar"));
    $array = stripslashes_deep($array);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In rails you can use .each do || to loop through the returned results
Can you cast a List<int> to List<string> somehow? I know I could loop through
You can, obviously, put a variable declaration in a for loop: for (int i
I know I can loop over the string or build a regex or invert
How can I build a loop in JavaScript?
How can I iterate over each file in a directory using a for loop?
How can polymorphism replace an if-else statement or Switch inside of a loop? In
If I have a for loop which is nested within another, how can I
Can somebody point me to a resource that explains how to go about having
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.