Jump to content


Photo

i am so confussed help radio buttons


  • Please log in to reply
5 replies to this topic

#1 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 September 2006 - 04:45 PM

advance thank you.

The radio buttion has a yes or no how do you display it back as a yes or no to edit with the users selected choose from the database cheers.

example of radio buttion.


<form method="POST" action="">
<br>
do you like redarrow
<br>
<input type="radio" name="like" value="yes" checked>yes
<input type="radio" name="like" value="no" >no
<br>
<br>
<input type="submit" name="submit" value="ansaw please">
</form>


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 17 September 2006 - 05:14 PM

<?php
if (isset($_POST['submit'])) {
    $likeme = $_POST['like'];
    echo $likeme;
// do whatever else you want ...
}
?>
<form method="POST" action="">
... more form code

Legend has it that reading the manual never killed anyone.
My site

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,023 posts

Posted 17 September 2006 - 05:57 PM

You need to compare the db field value with each of the button values. The one that matches is set as 'checked'.
<?php
$dbLike = 'yes';    // <---- value from database
?>
<form method="POST" action="">
<br>
do you like redarrow
<br>
<input type="radio" name="like" value="yes" <?php echo $dbLike=='yes' ? 'checked' : '' ?> >yes
<input type="radio" name="like" value="no"  <?php echo $dbLike=='no'  ? 'checked' : '' ?> >no
<br>
<br>
<input type="submit" name="submit" value="answer please">
</form>


If you have several possible values then it's easier to use an array and test each value in a loop.

<?php
$dbLike = 3;       // <---- value from database
?>
<form method="POST" action="">
<br>
do you like redarrow
<br>
<?php
    $likes = array (
        0 => "Who's he?",
        1 => "Really like the guy",
        2 => "He's OK",
        3 => "Neutral feelings",
        4 => "Not a lot",
        5 => "Hate the guy"
    );
    foreach ($likes as $val => $text) {
        $chk = $dbLike==$val ? 'checked' : '';
        echo "<input type='radio' name='like' value='$val' $chk> $text<br>";
    }
?>

<br>
<input type="submit" name="submit" value="answer please">
</form>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 September 2006 - 06:48 PM

Barand thank you so much another for the white board whale perfect and cheers andy grate stuff.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,023 posts

Posted 17 September 2006 - 06:49 PM

How big is this whiteboard? Must be getting pretty full ;D
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 September 2006 - 06:57 PM

gone throw 200 markers on the stats code lol.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users