value of select and radio using php -
i'm using php4 develoope small application , have small form , including radiobox , , selectbox.. insert of data , works ,now want try update form , have small problem ,i value of radiobox user check it, , same select.. 1 can me please. here code
<html> <head></head> <body> <?php include('connexion.php'); $id=$_get['idp']; $req="select * `personne` id='$id'"; $res=mysql_query(($req)); $ligne=mysql_fetch_row($res); ?> <form method="get" action="updatesubmit.php"> <table> <tr><td>nom:</td><td><input type="text" value="<?php echo $ligne[1] ?>" name="nom">*</td></tr> <tr><td>prenom:</td><td><input type="text" value="<?php echo $ligne[2] ?>" name="prenom">*</td></tr> <tr><td>email:</td><td><input type="email" value="<?php echo $ligne[3] ?>" name="email">*</td></tr> <tr><td>numero tel:</td><td><input type="text" value="<?php echo $ligne[4] ?>" name="tel"></td></tr> <tr><td>sexe:</td><td>h:<input type="radio" name="sexe" value="homme"> f:<input type="radio" required name="sexe" value="femme"> </td></tr> <tr><td>pays:</td><td> <select name="pays"> <option>australie</option> <option>france</option> <option>maroc</option> <option>tunisie</option> <option>usa</option> </select></td></tr> <tr><td><input type="submit" value="s'inscrire"></td></tr> </table> </form> </body> </html>
you should care mysql injection using pdo or : $id = (int) $_get['idp'];
select, in case data stored in $ligne[6]:
<select name="pays"> <option value='australie' <?php echo ($ligne[6]=='australie')? 'selected' : '' ; ?> >australie</option> <option value='france' <?php echo ($ligne[6]=='france')? 'selected' : '' ; ?> >france</option> <option value='maroc' <?php echo ($ligne[6]=='maroc')? 'selected' : '' ; ?> >maroc</option> <option value='tunisie' <?php echo ($ligne[6]=='tunisie')? 'selected' : '' ; ?> >tunisie</option> <option value='usa' <?php echo ($ligne[6]=='usa')? 'selected' : '' ; ?> >usa</option> </select>
and radiobox, in case data stored in $ligne[5]:
h:<input type="radio" name="sexe" value="homme" <?php echo ($ligne[5]=='homme')? 'checked' : '' ;?> > f:<input type="radio" name="sexe" value="femme" <?php echo ($ligne[5]=='femme')? 'checked' : '' ;?> >
Comments
Post a Comment