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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:18:09+00:00 2026-06-03T08:18:09+00:00

I have an odd issue. I have one PHP script that is used for

  • 0

I have an odd issue. I have one PHP script that is used for multiple forms. It takes in all the requests and then puts the data in the appropriate table in a database. As it stands, it looks like this:

    $fields = "";
$values = "";

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


        $key = str_replace(":","",$key);
        $fields .= "$key,";
        $values .= "'$value ',";
}


//remove the ending comma from $fields and $values
$fields = substr($fields, 0, -1);
$values = substr($values, 0, -1);

$sql = "INSERT INTO " . $survey . " ($fields) VALUES ($values)";
mysql_query($sql)
    or die(mysql_error());

And this works well. The problem is, there are some forms with checkboxes (i.e. a person can select more than one option). If I were to use a get method, the query string would look like:

http://www.somesite.php?V9=1&V9=2&V9=4

With the current script, only 4 is taken, since it was the last value.

Now, I know a reason this is happening is because of the way the name of the checkbox is defined in the form. It says name=”V9″ instead of name=”V9[]” However, I cannot change the forms. They are generated by software, and the idea is that any user can create an HTML form, point it to the script and their information will be recorded in a table. So, changing the HTML is not an option for me.

So, I need a way to detect whether a key has been submitted, and if so, append the value. I tried this:

    $fields = "";
$values = "";

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

        //check to see if the key has already been used for multi-choice questions
        $key_check = strpos($fields, "$key,");

        if($key_check !== false){
            $values = substr($values, 0, -2);
            $values .= "\;$value ',";
        }else{
            $key = str_replace(":","",$key);
            $fields .= "$key,";
            $values .= "'$value ',";
        }
}


//remove the ending comma from $fields and $values
$fields = substr($fields, 0, -1);
$values = substr($values, 0, -1);

$sql = "INSERT INTO " . $survey . " ($fields) VALUES ($values)";
mysql_query($sql)
    or die(mysql_error());

But I get the same results. $key_check never seems to be valid. Any help would be appreciated. Someone here has a working ASP version that does a similar thing, but it emails the data, rather than saving it in a DB.

  • 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-03T08:18:10+00:00Added an answer on June 3, 2026 at 8:18 am

    You could try this if you are using $_GET:

    function convertInput($qs=""){
      $rtn = "";
      $holdingArray = array();
      if(trim($qs)!=""){
        $vars = explode("&", $qs);
        foreach($vars as $val){
          $kv = explode("=", $val);
          if(count($kv)==2){
            if(isset($holdingArray[$kv[0]])){
              $holdingArray[$kv[0]] .= "," . $kv[1];
            }else{
              $holdingArray[$kv[0]] = $kv[1];
            }
          }
        }
        $rtn = $holdingArray;
      }
      return $rtn;
    }
    print_r(convertInput($_SERVER["QUERY_STRING"]));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an odd issue while using FlashCS4. I have a textfield that, when
I have a simple script that should cause one of three divs to be
I have a really odd issue with WMI that I'm running into on a
So I have a rather odd issue that I wanted to see if anyone
An odd issue that I have been trying to address in a project -
I have a very odd issue. When I execute a specific database stored procedure
I have an odd linq subquery issue. Given the following data structure: Parents Children
I am learning JQuery, and I have ran into an odd issue. I made
This is very odd. I have never had this issue with ShowDialog in C#.
I have an odd problem with Django. I have a set of objects that

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.