Jump to content

Search the Community

Showing results for tags 'multiple radio buttons'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. Hey, I'm trying to insert dynamically generated radio buttons form to the db, but this code below inserts always first group(id) with always selected value 1. How can I insert all groups(ids) with proper value?? Here's what I have. Table radio_form `radio_form` (`name_id`, `name1`, `name2`) (1, 'Nike', 'Addidas'), (2, 'Google', 'Bing'), (3, 'Apple', 'Microsoft'), (4, 'Coca-Cola', 'Pepsi'), (5, 'Snowboard', 'Ski'), (6, 'Car', 'Bike'), (7, 'Futbol', 'Rugby'), (8, 'Hot', 'Cold'); Form page (hidden input to insert id of the group to the db) <?php if (isset($_POST['hide_id'], $_POST['selected'])) { $name_id = $_POST['hide_id']; $item_select = $_POST['selected']; $errors = array(); if (empty($_POST['selected'])) { $errors[] = 'All fields required!'; } if (!empty($errors)){ foreach ($errors as $error) { echo '<div id="error">', $error, '</div><br />'; } } else { $name_id = (int)$_POST['hide_id']; $user_id = $_SESSION['user_id']; $item_select = (int)$_POST['selected']; $query = "INSERT INTO `selection` VALUES ('$name_id', '$user_id', '$item_select')"; mysql_query($query); echo "<br />OK<br />"; /*header('Location: index.php'); exit();*/ } } ?> <form action="" method="POST" id="go" name="go"> <?php $items = get_items(); foreach($items as $item){ echo $item['name_id']; ?> <label for ="<?php echo $item['name1']; ?>"> <input type ="hidden" name="hide_id[<?php echo $item['name_id']; ?>]" value="<?php echo $item['name_id']; ?>"> <?php echo $item['name1']; ?> <input type ="radio" id="<?php echo $item['name1']; ?>" name="selected[<?php echo $item['name_id']; ?>]" value="1" /> </label> <input type ="radio" id="<?php echo $item['name2']; ?>" checked name="selected[<?php echo $item['name_id']; ?>]" value="2" /> <label for ="<?php echo $item['name2']; ?>"> <?php echo $item['name2']; ?> </label><br /> <?php } ?> <br /><br /> <button type ="submit" id="send" name="send">Send</button> </form> print_r($_POST); Array ( [hide_id] => Array ( [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 [7] => 7 [8] => 8 ) [selected] => Array ( [1] => 2 [2] => 2 [3] => 1 [4] => 2 [5] => 2 [6] => 1 [7] => 1 [8] => 2 ) [send] => )
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.