0

Good day every one, i am trying to check if a radio button were clicked, and iwant the value of that clicked radio button to pass on a variable, i will used that variable to compare records in database with the same values from it. and display all records on list box?? but when i try to run this code nothings happen

<td><input type="radio" name="1stChoice" value="TESDA" ></td><br>

<td align = "center">

<select name="course1">

<?php
include('dbconnection.php');
if(isset($_POST['1stChoice'])) {
if($_POST['1stChoice'] == 'TESDA') {
$choose='TESDA';
} elseif($_POST['1stChoice'] == 'CHED') {
$choose='CHED';
}
}
$mysql_select=mysql_query("select * from courses where Institution = '$choose' ",$mysql);

while($row=mysql_fetch_array($mysql_select))
{

?>
<option><?php $row['Program']; ?></option></td>
</select>
<?php } ?>
</tr>
<td width="20%">2nd choice:</td>
<td><input type="radio" name="2ndChoice" value="CHED" ></td>
<td><input type="radio" name="2ndChoice" value="TESDA" ></td><br>
<td align = "center">
<select name="course2">
<?php
include('dbconnection.php');
if(isset($_POST['2ndChoice'])) {
if($_POST['2ndChoice'] == 'TESDA') {
$choose='TESDA';
} elseif($_POST['2ndChoice'] == 'CHED') {
$choose='CHED';
}
}
$mysql_select=mysql_query("select * from courses where Institution = '$choose' ",$mysql);

while($row=mysql_fetch_array($mysql_select))
{

?>
<option><?php $row['Program']; ?></option></td>
</select>
<?php } ?>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
reymar
  • 5
  • 4

2 Answers2

1

I tested your code and as far as I can see, you're not echoing your <?php $row['Program']; ?> which should read as <?php echo $row['Program']; ?>

This is for both your <option> tags.

I also didn't notice any form tags <form></form>, so you will need to add those if you're not presently using them.

Using a submit button could be useful also. Although I'm not sure if you're using JS/jQuery with your code.

<input type="submit" name="submit" value="Submit">


Here is what I used to test it with, along with a few additions/modifications:

(I added form tags, a submit button and the echo for the <select> tags)

<form action="" method="post">
<td><input type="radio" name="1stChoice" value="TESDA" ></td><br>

<input type="submit" name="submit" value="Submit">

<td align = "center">

<select name="course1">

<?php
include('dbconnection.php');
if(isset($_POST['1stChoice'])) {
if($_POST['1stChoice'] == 'TESDA') {
$choose='TESDA';
} elseif($_POST['1stChoice'] == 'CHED') {
$choose='CHED';
}
}
$mysql_select=mysql_query("select * from courses where Institution = '$choose' ",$mysql);

while($row=mysql_fetch_array($mysql_select))
{

?>
<option><?php echo $row['Program']; ?></option></td>
</select>
<?php } ?>
</tr>
<td width="20%">2nd choice:</td>
<td><input type="radio" name="2ndChoice" value="CHED" ></td>
<td><input type="radio" name="2ndChoice" value="TESDA" ></td><br>
<td align = "center">
<select name="course2">
<?php
include('dbconnection.php');
if(isset($_POST['2ndChoice'])) {
if($_POST['2ndChoice'] == 'TESDA') {
$choose='TESDA';
} elseif($_POST['2ndChoice'] == 'CHED') {
$choose='CHED';
}
}
$mysql_select=mysql_query("select * from courses where Institution = '$choose' ",$mysql);

while($row=mysql_fetch_array($mysql_select))
{

?>
<option><?php echo $row['Program']; ?></option></td>
</select>
</form>
<?php } ?>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • You're welcome @reymar Do click the white gray outline checkmark (next to my answer) till it turns Green so the question will have been answered. This is the way the SO system works, cheers. – Funk Forty Niner Apr 23 '14 at 18:30
0

This is not a php work. IF your html is good, your browser will check the checked radio button. See! In your code, name must start with a letter or a _(underscore). So, replace all name='2ndChoice' with

   <td><input type="radio" name="ck_2ndChoice" value="CHED" ></td>
   <td><input type="radio" name="ck_2ndChoice" value="TESDA" ></td><br>

and all name='1stChoice' with name='ck_1stChoice'

Bellash
  • 7,560
  • 6
  • 53
  • 86