Khazz T. Khazz T. - 6 months ago 11
MySQL Question

Select any data from mysql using radio button in php

i want to get all email address list form database and want to be able to select any email address using redio button. Following codes can show list of all email address but not working for selecting them using HTML redio button. what wrong i am doing?

$result = mysql_query("SELECT * FROM users");
while($row = mysql_fetch_array($result)) {
//
$allemail = array($row['w_email']);
foreach ( $allemail as $email_show) {
// echo "$email_show"; // this echo shows all my database email successfully!
echo "<form action="" method="post"><input type="radio" name="email_selector" value="$email_show"><br></form>"; //but this code not works
}
}



Parse error: syntax error, unexpected '" method="'
(T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';' in
C:\xampp\htdocs\phpprojects\plapp\admin89\dashboard.php on line 22

Answer

Because you every time creating new form which is not required just create one form and then make the loop for radio buttons like

$result = mysql_query("SELECT * FROM users");
echo "<form action='' method='post'>";
while($row = mysql_fetch_array($result)) {

    $email_show = $row['w_email'];
    echo "<input type='radio' name='email_selector' value='$email_show'><br>"; 
}
echo "</form>";
Comments