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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:17:01+00:00 2026-05-30T05:17:01+00:00

I am saving data to a mysql database and these are going to be

  • 0

I am saving data to a mysql database and these are going to be different options, rather then having them in their own column i am trying to to keep them in the same.

So like surface in mysql would look like : grass,pavement,tarmac – i can get the data to show, but i cannot for some reason get it to save, after either adding a new option or deleting an option.

EDIT – This is now working, i reposted it on here incase others needs help! Thanks

Add:

    $surface = mysql_real_escape_string($_POST['surface']);
    $array = explode(',',$setQuery['Surface']);
    $new_array = implode(',',$array).','.$surface;
    $saveSettings = mysql_query("UPDATE `settings` SET Surface = '$new_array' WHERE id = '1'");

Delete:

    $surface = mysql_real_escape_string($_GET['s']);
    $array = explode(',',$setQuery['Surface']);
    unset($array[$surface]);
    $new_array = implode(',',$array);
    $saveSettings = mysql_query("UPDATE `settings` SET Surface = '$new_array' WHERE id = '1'");

Thanks for any help
regards

  • 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-30T05:17:03+00:00Added an answer on May 30, 2026 at 5:17 am

    Having used a for loop to build your array into a comma-separated string sent you down the wrong path.

    The correct course of action here is to use the PHP built-in implode() to construct the string from your array:

    $new_array = implode(",", $array);
    

    I notice also that your add method reads input from $_POST['s'] while the delete method reads from $_GET['s']. Check the consistency between these, if it is an issue.

    In either case, however, you must call mysql_real_escape_string() to properly escape it against SQL injection. That is best done just before inserting it into the SQL string, after you have added or deleted from the array and called implode().

    // All changes add/del made to array already...
    $new_array = implode(",", $array);
    $new_array = mysql_real_escape_string($new_array);
    
    $saveSettings = mysql_query("UPDATE `settings` SET Surface = '$new_array' WHERE id = '1'");
    // Use error handling methods:
    if (!$saveSettings) {
      // Something went wrong
      echo mysql_error();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When saving data in different sql tables, is it best to use the GUID
I really like Xml for saving data, but when does sqlite/database become the better
I have a action class for saving some data to a database.In action class
I want to do encode the data before saving it to a database table
I've a bunch of data stored in a mysql database as a bunch of
I am saving to the database from cakephp to mysql. When I view the
I am saving a serialized object to a mysql database blob. After inserting some
I'm saving contents of a particular div in mysql database as html elements. So
Saving data to Postscript in my app results in a Postscript file which I
What's the right way to go about saving data like Pages, Numbers and other

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.