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

  • Home
  • SEARCH
  • 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 7754233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:15:21+00:00 2026-06-01T12:15:21+00:00

I have 2 arrays, $arr for the old menu name, and $arr1 for the

  • 0

I have 2 arrays, $arr for the old menu name, and $arr1 for the new menu name. I want to replace the old menu name with the new in my database. I have the following code but it throws out an error.

<?php
$arr  = explode(',', preg_replace('/^.*\[(.*)\].*$/', '$1', trim($_POST['menuname'],
                                                                 '[]')));
$arr1 = explode(',', preg_replace('/^.*\
       [(.*)\].*$/', '$1', trim($_POST['editmainmenu'], '[]')));

mysql_connect("localhost", "root", "root");
mysql_select_db("test");
foreach ($arr as $key => $value)
{
    $value1 = $arr1[$key];

    mysql_query("update test set (menuname) =('" .
                    mysql_real_escape_string($value1) . "') where menuname=('" .
                    mysql_real_escape_string($value) . "')")or
        die('unable' . mysql_error());
    echo "updated";
}
?>

I get the following error:

04-09 19:06:27.201: I/System.out(1291): unableYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(menuname) =('') where menuname=('Food Menu')' at line 1

Please tell me how to solve this issue. Thanks!

  • 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-06-01T12:15:23+00:00Added an answer on June 1, 2026 at 12:15 pm

    This is what your code looks like after the cleanup I did to it:

    <?php
    $old_menu_names = explode(',',
                              preg_replace(
                                  "|\[(.+)\]|",          //Find the part in between the square brackets
                                  "$1",                  //And extract it
                                  trim(
                                      $_POST['menuname'] //From the trimmed menuname.
                                  )
                              )
    );
    $new_menu_names = explode(',',
                              preg_replace(
                                  "|\[(.+)\]|",
                                  "$1",
                                  trim(
                                      $_POST['editmainmenu']
                                  )
                              )
    );
    
    mysql_connect("localhost", "root", "root");
    mysql_select_db("test");
    foreach ($old_menu_names as $key => $old_name)
    {
        $new_name = mysql_real_escape_string($new_menu_names[$key]);
        $old_name  = mysql_real_escape_string($old_menu_names[$key]);
    
        mysql_query("UPDATE `test` SET `menuname` = '$new_name' WHERE menuname = '$old_name'")
            or die('Error' . mysql_error());
        echo "Updated";
    }
    ?>
    

    ##What I did:

    • Variable naming – Name your variables according to what they contain, don’t use obscure names such as $arr or $arr1, in larger applications, you’ll be lost in no time.
    • If a statement is long, complex, and/or contains nested brackets, don’t be afraid to line break it so that it would be easier to follow.
    • Comments, when something is not immediately understood, feel free to add comments explaining to anyone (including yourself in a few months) what the code is intended to do.
    • Don’t add brackets where they’re not needed. See the new query I wrote.
    • You didn’t declare the old name inside your foreach loop, so that came out empty the threw an error.

    In short, I suggest you read a good book about best practices and programming concepts.

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

Sidebar

Related Questions

I have some js arrays and I want to find the arrays by name.
I wrote below code to compare to arrays that have same elements but in
Suppose I have the following data: var arr = [], arr1 = [], arr2
Right now, I have: public <T> T[] toArray(T[] old) { T[] arr = Arrays.copyOf(old,
I have this code here that has two arrays. It sorts arr[] , so
Hi when I have an array in actionscript var arr : Array = new
Let's say I have array of bytes: byte[] arr = new byte[] { 0,
I have an array of integers in string form: var arr = new string[]
I have following 2 dimensional array input: var arr = [ ['A', ['Sun','Moon']], ['B',
I have arrays like this. [11] => Array ( [transactioncurrencyid] => Array ( [!name]

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.