Jump to content

associate radiobuttons with selected value from dropdownbox


snakebe

Recommended Posts

I have made the following code to show a dropdownbox filled with data from a mysql-database.

It also shows 2 radiobuttons. What I don't know is how to associate the radiobuttons with the selected data in the dropdown.

 

For example, I select the person 'Bill' from the dropdownbox, then if I select one of the radiobuttons and I submit the values, I want that value to be inserted/updated in the database for the user 'Bill'.

 

With the code I have it just inserts a new record in the database..

 

<select name="naam">

<?php 
$dbuser = "****";
$dbpass = "****";
$dbhost = "****";

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');

$dbname = '****;
mysql_select_db($dbname);

$sql2="SELECT * from kerstfuif order by achternaam";
$result2=mysql_query($sql2) or die(mysql_error());

?>

<?php
if(mysql_num_rows($result2)==1){
    	$item = mysql_fetch_assoc($result2);

	echo $item["voornaam"] . " " . $item["achternaam"];

	}

while ($dropdown=mysql_fetch_Array($result2)){
                         
    if ($dropdown["naam"]==''){
      
        echo("<option selected value = " .$dropdown["achternaam"]." > ".$dropdown["achternaam"]." ".$dropdown["voornaam"]."  |  code: ".$dropdown["code"]." </option>");
                 
}else{
      }
}

?> 
</select> 
</td>
</table> 
<form method="POST" action="2.php">
      <input type="radio" name="keuze" value="0" /> nog niet betaald<br />
      <input type="radio" name="keuze" value="1" checked /> betaald<br />
      <input type="submit" name="betaald" value="voeg toe" />
      </form>
     
 <?php

      if ($_SERVER['REQUEST_METHOD'] == "POST") {

$betaald = $_POST['keuze'];

$SQL = " INSERT INTO kerstfuif ";
$SQL = $SQL . " (betaald) VALUES ";
$SQL = $SQL . " ('$betaald') ";
$result = mysql_db_query($dbname,"$SQL",$conn);

if (!$result) {
    echo("ERROR: " . mysql_error() . "\n$SQL\n"); }

echo ("Je gegevens zijn goed ontvangen\n");

}
     ?>

Link to comment
Share on other sites

The select should be inside your form to recieve the selected user on submittion. To update the user `Bill`, you then have to insert into table "WHERE user='Bill'" (if the column is named "user").

 

$user = $_POST['naam'];
$betaald = $_POST['keuze'];

$SQL = " UPDATE kerstfuif SET betaald='$betaald' WHERE user='$user'";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.