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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:22:04+00:00 2026-05-27T22:22:04+00:00

I’m cutting my teeth on extjs and running into an issue. I have a

  • 0

I’m cutting my teeth on extjs and running into an issue. I have a function that is updating from a grid table, and I’m trying to send the “success” back to the browser in a JSON encoded statement. If I only update a single value, it works fine. If I update multiple values (from an array), however, the response is sent for each, thus causing an error. How can I give one response for the total array?

Code below:

    $conn   = mysql_connect ('localhost', 'root', '') or die (mysql_error ());
    mysql_select_db ('cptestdata', $conn ) or die (mysql_error ());

    $json_string = file_get_contents("php://input");
    $obj = json_decode($json_string, true);

    // check for single update value. if so, create array wrapper
        if(!isset($obj [0])) {
            $temp = array();
            $temp[] = $obj;
        $obj = $temp;
        }
        foreach ($obj as $value) {

            $option_id      = $value['option_id'];  
            $option_val     = $value['option_value'];   

                $option_q   = "
                        UPDATE wp_options
                        SET option_value='".$option_val."'
                        WHERE option_id='".$option_id."'
                        ";


                mysql_query($option_q);


                // json output to notify the insert is success or not
                if ($option_q) {
                        echo '{"success":"true"}';
                }
                else {
                        echo '{"success":"false"}';
                }
        } // endforeach
  • 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-27T22:22:05+00:00Added an answer on May 27, 2026 at 10:22 pm

    Remove the echo from the loop, like this:

        $conn   = mysql_connect ('localhost', 'root', '') or die (mysql_error ());
        mysql_select_db ('cptestdata', $conn ) or die (mysql_error ());
    
        $json_string = file_get_contents("php://input");
        $obj = json_decode($json_string, true);
    
        // check for single update value. if so, create array wrapper
            if(!isset($obj [0])) {
                $temp = array();
                $temp[] = $obj;
            $obj = $temp;
            }
            $success = TRUE;
            foreach ($obj as $value) {
    
                $option_id      = $value['option_id'];  
                $option_val     = $value['option_value'];   
    
                    $option_q   = "
                            UPDATE wp_options
                            SET option_value='".$option_val."'
                            WHERE option_id='".$option_id."'
                            ";
    
    
                    mysql_query($option_q);
    
                    if (!$option_q)
                      $success = FALSE;
    
    
            } // endforeach
    
            // json output to notify the insert is success or not
            if ($success) {
                    echo '{"success":"true"}';
            }
            else {
                    echo '{"success":"false"}';
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post

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.