InLikeMe Posted November 27, 2008 Share Posted November 27, 2008 Hello everyone! I have a problem with radio buttons and php. I'm trying to pass the value of the radio button that has been selected, to another page. I have a query: $query = sprintf("SELECT bungalow_id, name, description, pricepernight, beds FROM bungalows WHERE bungalow_id <> ALL (SELECT bungalow_id FROM bungalow_diary WHERE date BETWEEN '$checkin_year-$checkin_month-$checkin_day' AND '$checkout_year-$checkout_month-$checkout_day')"); $check_date = mysql_query($query); And then the code: <?php while ($row = mysql_fetch_assoc($check_date)) { ?> <div id="heading"> <input type="radio" name="chosen_bunga" value= "<?php echo $row['bungalow_id']; ?>"> <?php echo $row['bungalow_id']; echo $row['name']; ?> </div> <div id="description"> <?php echo $row['description']; ?> <br> Price: <?php echo $row['pricepernight']; ?> euro <br> No of beds: <?php echo $row['beds']; ?> <br> </div> <?php } ?> <FORM name ="form1" method ="post" action ="./yourdetails.php"> <input type="hidden" name="chosen_name" value="rosana" > <input type="hidden" name="chosen_bunga_name" value="<?php echo $_POST["chosen_bunga"]; ?>"> <input type="submit" name="book_submit" value="Book"> </FORM> Now the "yourdetails.php" contains the following: <?PHP $selected_bunga = $_POST['chosen_name']; $test = $_POST['chosen_bunga_name']; print $selected_bunga; print $test; ?> So when I press the "Book" button, appears the "youdetails.php" page showing $test value which is "rosana". However the $selected_bunga has nothing in it, so it doesnt show anything. Obviously the $chosen_bunga_name although it should, hasn't taken the value of the chosen radio button(value= "<?php echo $row['bungalow_id']; ?>"). Why does this happen? I wonder if it is perplexed because of the query. Any opinions? Thanx in advance! Link to comment https://forums.phpfreaks.com/topic/134478-radio-buttons-php/ Share on other sites More sharing options...
willpower Posted November 27, 2008 Share Posted November 27, 2008 Firstly you while statement is not within your form therefore you value will neve be passed. Secondly you need to you a radioGroup. That way when you neame the group the value can be passed. Will Link to comment https://forums.phpfreaks.com/topic/134478-radio-buttons-php/#findComment-700241 Share on other sites More sharing options...
GKWelding Posted November 27, 2008 Share Posted November 27, 2008 Use the following instead. It'll work much better for you. <FORM name ="form1" method ="post" action ="./yourdetails.php"> <?php while ($row = mysql_fetch_assoc($check_date)) { ?> <div id="heading"> <input type="radio" name="chosen_bunga" value= "<?php $row['bungalow_id']; ?>"> <?php echo $row['bungalow_id']; echo $row['name']; ?> </div> <div id="description"> <?php echo $row['description']; ?> <br/> Price: <?php echo $row['pricepernight']; ?> euro <br/> No of beds: <?php echo $row['beds']; ?> <br/> </div> <?php } ?> <input type="submit" name="book_submit" value="Book"> </FORM> Link to comment https://forums.phpfreaks.com/topic/134478-radio-buttons-php/#findComment-700247 Share on other sites More sharing options...
InLikeMe Posted November 27, 2008 Author Share Posted November 27, 2008 I've placed the radio buttons within the while statement and I've also added the radiogroup (I found its syntax is like this) <FORM name ="form1" method ="post" action ="./yourdetails.php"> <radiogroup id="chosen_bunga"> <?php while ($row = mysql_fetch_assoc($check_date)) {?> <div id="heading"> <radiobutton value= "<?php $row['bungalow_id']; ?>"/> <?php echo $row['bungalow_id']; echo $row['name']; ?> </div> <div id="description"> <?php echo $row['description']; ?> <br> Price: <?php echo $row['pricepernight']; ?> euro <br> No of beds: <?php echo $row['beds']; ?> <br> </div> <?php } //end of while ?> </radiogroup> <input type="hidden" name="chosen_name" value="rosana" > <input type="hidden" name="chosen_bunga" value="<?php echo $_POST["chosen_bunga"]; ?>"> <input type="submit" name="book_submit" value="Book"> </FORM> ...but now no radio buttons appear . I think it doesnt understand the <radiogroup> or <radiobutton> command. Isnt it a javascript object? @GKWelding Neither with that code works. The following line isnt necessary? --> <input type="hidden" name="chosen_bunga" value="<?php echo $_POST["chosen_bunga"]; ?>"> Link to comment https://forums.phpfreaks.com/topic/134478-radio-buttons-php/#findComment-700305 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.