0

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

Bustikiller
  • 2,423
  • 2
  • 16
  • 34
Khazz T.
  • 167
  • 1
  • 1
  • 5
  • 1
    how is this question related to CSS? – Dhaval Chheda May 19 '16 at 06:01
  • **WARNING**: If you're just learning PHP, please, do not learn the obsolete [`mysql_query`](http://php.net/manual/en/function.mysql-query.php) interface. It's awful and has been removed in PHP 7. A replacement like [PDO is not hard to learn](http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/) and a guide like [PHP The Right Way](http://www.phptherightway.com/) helps explain best practices. Make **sure** your user parameters are [properly escaped](http://bobby-tables.com/php) or you will end up with severe [SQL injection bugs](http://bobby-tables.com/). – tadman May 19 '16 at 06:13

2 Answers2

0

You have few mistakes.

Use, form tag before while, as it is creating a new form each time loop executes.

Use this piece of code:

echo "<form action='' method='post'>";

    while(loop)
    {
    *code

    echo "<input type='radio' name='email_selector' value=".$email_show."><br>"; 
    }
    echo "</form>";

And, As per tadman's comment "try to learn PDO and implement the same".

srssatya
  • 46
  • 4
  • yes your code works but problem is i cant select any single email from redio button. when i select one redio its get selected permanently and not changed when i selecting another redio button. – Khazz T. May 19 '16 at 06:25
  • Ya, because, every time your while loop executes, anew form has been created. – srssatya May 19 '16 at 06:34
  • Please see the edited answer, And if it helps mark as solved one.Thanks – srssatya May 19 '16 at 06:39
0

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>";
DD77
  • 776
  • 2
  • 8
  • 25