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");

}
     ?>

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'";

Archived

This topic is now archived and is closed to further replies.

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