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 6111431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:37:47+00:00 2026-05-23T14:37:47+00:00

I have this : foreach($textnode as $key => $value) { $value = stripslashes($value); $value

  • 0

I have this :

foreach($textnode as $key => $value) {

$value = stripslashes($value);
 $value = mysql_real_escape_string($value, $con);


 mysql_query("INSERT INTO paragraphs (textnodes, url)
 VALUES ('$value', '$url')");



}

My table has three columns (textnodes, ytext, and url)

textnode and ytext are both arrays…..can I do this for two arrays?

  • 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-23T14:37:47+00:00Added an answer on May 23, 2026 at 2:37 pm

    I think what you want is to use a normal for loop instead:

    for($i=0;$i<sizeof($textnode);$i++){
    
        $textnode[$i] = stripslashes($textnode[$i]);
        $textnode[$i] = mysql_real_escape_string($textnode[$i], $con);
    
        $ytext[$i]    = stripslashes($ytext[$i]);
        $ytext[$i]    = mysql_real_escape_string($ytext[$i], $con);
    
         mysql_query("INSERT INTO paragraphs (paragraphs, ytext, url)
         VALUES ('$textnode[$i]', '$ytext[$i]', '$url')");
    
    }
    

    That way you can loop through both at once (not 100% sure that’s what you were asking, but it’s my best guess).


    I haven’t tested the code above but it should work. However the style it follows and the style you’ve shown above isn’t very good. Here are a few improvements that could be made:

    1. Instead of making a separate query for each insert, do all the inserts in one query. This is better because there is only overhead for 1 query instead of $i queries.

    2. Abstract away the DB. Currently it seems that you are mixing business logic with DB logic. I can see this because you are escaping strings of text with specific purposes (textnode and ytext and url) and inserting them with a mysql query. Instead it would be prudent to abstract away the query so that the business logic isn’t coupled with the db logic.

    3. A smaller note – you shouldn’t have to call stripslashes. If you are using magic quotes, disable it immediately instead, as it is deprecated and is considered a bad practice now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this: foreach($_POST as $key => $value) { $data[$key] = filter($value); } filter();
I have this: foreach ($country as $value){ The contents of $country using print_r is
I have this code foreach my $key (keys %ad_grp) { # Do something }
I have this foreach -loop: foreach (var classId in m_ClassMappings[taAddressDefinition.Key]) { if(!m_TAAddressDefinitions.ContainsKey(classId)) { m_TAAddressDefinitions.Add(classId,
I have this code: foreach($summary as $machine) { $hostname = $machine['node']; $result = mysql_query(SELECT
I have this code here, {foreach from=$cart.cartItems item=item name=cart} <div id=cart2Produkt> <p>{if $item.Product.ID} <a
I have this code while($row = mysql_fetch_row($result)) { echo '<tr>'; $pk = $row[0]['ARTICLE_NO']; foreach($row
I have the following code: foreach (var control in this.Controls) { } I want
I have a function that looks something like this: //iteration over scales foreach ($surveyScales
I have code that I want to look like this: List<Type> Os; ... foreach

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.