0

Hi
How can I pass value of my radio buttons to my form.php code?

I will be very thankfull for your answer.

<form action="form1.php" method="post">
First name:  <input type="text" name="fname"><br><br>
Last name:  <input type="text" name="lname"><br><br>

<h3>What is the best programming language to learn for hacking</h3>
Python
<input type="radio" name="rb_python" value="Python"><br>
Perl
<input type="radio" name="rb_perl" value="Perl"><br>
Java
<input  type="radio" name="rb_java" value="java"><br>

<input type="submit" name="submit" value="Submit"><br>
</form>
3
Contributors
7
Replies
39
Views
3 Years
Discussion Span
Last Post by tony75
0

Ok thanks
But what about php coden?

<input type="radio" name="hack_language" value="Python"><br>
Perl
<input type="radio" name="hack_language" value="Perl"><br>
Java
<input  type="radio" name="hack_language" value="java"><br>

I think my php code is wrong.

#form.php
$python_status = "unchcked";
$perl_status = "unchcked";
$java_status = "unchcked"; 
if(isset($_POST["submit"])){
    $selected_radio = $_POST["hack_language"];
    if ($selected_radio == "Python"){
        $python_status = "checked";

    }
    elseif($selected_radio == "Perl"){
        $perl_status = "checked";
        echo "You select" .
    }
    else
    {
        if($selected_radio == "java")
        $java_status ="checked";
    }


}

Edited by tony75

0

In your Action page just print Value using

$_POST('hack_language')

<?php echo $_POST('hack_language'); ?>
0

Give radio options a default checked in the form if possible, to ensure a value if always sent.

$selected_radio = $_POST["hack_language"];
echo "You selected $selected_radio";
0

Thanks so much
what about else i got error?

 else
{
if($selected_radio == "java")
$java_status ="checked";
}
}
0

Our code means you don't need all those conditionals...

if(isset($_POST["submit"])){
    $selected_radio = $_POST["hack_language"];
    echo "You selected $selected_radio";
}

That's it - no need for anything else. Unless you want to do soemthing else?

Edited by diafol

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.