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

The Archive Base Latest Questions

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

I have a form selection that allows users to select a product from a

  • 0

I have a form selection that allows users to select a product from a dynamically generated MySQL list and then rate the product using radio buttons.

<input type="checkbox" value="$row[ProdID]" name="Product[]" id="Product$row[ProdID]" onclick="showhide_div($row[ProdID])" />$row[ProductName]

<div id="div$row[CatID]" style="display:none">
<input type="radio" name="ProductQual$row[ProdID]" id="PQ$row[ProdID]" value="1" /> Poor&nbsp;&nbsp;
<input type="radio" name="ProductQual$row[ProdID]" id="PQ$row[ProdID]" value="2" /> Fair&nbsp;&nbsp;
<input type="radio" name="ProductQual$row[ProdID]" id="PQ$row[ProdID]" value="3" /> Good&nbsp;&nbsp;
<input type="radio" name="ProductQual$row[ProdID]" id="PQ$row[ProdID]" value="4" /> Excellent&nbsp;&nbsp;
</div>

I want to put the selected radio value for each of the “checked” products into a MySQL table

-----------------
| ProdID(a) | 3 |
| ProdID(b) | 1 |
-----------------

I know I need to for_each each selected Product but I am having trouble figuring out how to related the correct radio button from the overall $POST to the Product during the for_each loop to put the values into the MySQL table.

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

    There may be a more elegant way of doing things, but this would be my solution. I wrapped your checkboxes and radios in <label></label> tags, so the text is clickable (a good accessibility guideline to practice, too). RADIOs are generated with a unique ID for each product.

    <?php
    
    echo '<label><input type="checkbox" name="product_' . $row['ProdID'] . '" id="product_' . $row['ProdID'] . '" onclick="javascript:showhide_div(' . $row['ProdID'] . ')" /> ' . $row['ProductName'] . '</label>';
    
    echo <<<EOT
    <div id="div{$row['ProdID']}" style="display:none;">
    <label><input type="radio" name="productquality_{$row['ProdID']}" value="1" /> Poor</label>
    <label><input type="radio" name="productquality_{$row['ProdID']}" value="2" /> Fair</label>
    <label><input type="radio" name="productquality_{$row['ProdID']}" value="3" /> Good</label>
    <label><input type="radio" name="productquality_{$row['ProdID']}" value="4" /> Excellent</label>
    </div>
    EOT;
    

    And on the back-end, all ratings fields are parsed and inserted into a table.

    <?php
    
    foreach ( $_REQUEST as $k=>$v){   // Step through each _REQUEST (_POST or _GET) variable
    
        if ( strpos( $k, 'productquality' ) !== false ){    // Only parse productquality_X variables
            $parts = explode( '_', $k );    // Split at the underscore
            $id = $parts[1];    // ID is the part after the underscore
    
            // Do something, like insert into MySQL.  In reality best to escape the values, to make sure to prevent injection.
            mysql_query( ' INSERT INTO `quality` ( ProdID, Rating ) VALUES ( ' . $id . ', ' . $v . '); ');
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form with a select list that allows users to choose multiple
I have a django form that allows a user to select multiple options: CARDS
I have setup a form that allows a user to make selections from drop-down
within a form I have a section that allows the user to build out
I have a form that uses formcheck (a MooTools class that allows you to
We have a project that sets the DataSource of a combobox, but allows users
I have a php script that allows users to upload multiple files to server
I have a PHP script that allows users to enter grades by selecting a
I have a registration form with common registration fields and two multiple selection Lists
I have form that displays several keywords (standard set of choice lists that changes

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.