1

I am a newbie in PHP. I have a form like below:

<div class="col-xs-2 col-xs-offset-1">
    <input id="radio-ge-1" class="radio-custom" name="radio-ge" type="radio" value="1" checked>
    <label for="radio-ge-1" class="radio-custom-label tooltips">1 <span>Impossible to get marks</span></label>
</div>
<div class="col-xs-2">
    <input id="radio-ge-2" class="radio-custom" name="radio-ge" value="2" type="radio">
    <label for="radio-ge-2" class="radio-custom-label tooltips">2 <span>You have to work hard to get marks</span></label>
</div>
<div class="col-xs-2">
    <input id="radio-ge-3" class="radio-custom" name="radio-ge" value="3" type="radio">
    <label for="radio-ge-3" class="radio-custom-label tooltips">3 <span>The usual, just like any other class</span></label>
</div>


<div class="col-xs-2 col-xs-offset-1">
    <input id="radio-sl-1" class="radio-custom" name="radio-sl" value="1" type="radio" checked>
    <label for="radio-sl-1" class="radio-custom-label tooltips">1 <span>Unbearable pressure</span></label>
</div>
<div class="col-xs-2">
    <input id="radio-sl-2" class="radio-custom" name="radio-sl" value="2" type="radio">
    <label for="radio-sl-2" class="radio-custom-label tooltips">2 <span>High pressure, But doable</span></label>
</div>
<div class="col-xs-2">
    <input id="radio-sl-3" class="radio-custom" name="radio-sl" value="3" type="radio">
    <label for="radio-sl-3" class="radio-custom-label tooltips">3 <span>Fair, just like any other class</span></label>
</div>

I'm trying to save both radio buttons value in PHP by using the code:

$g_Easiness = $_POST['radio-ge'];
$s_Load = $_POST['radio-sl'];

But in this case, I'me only getting the first button's value. Second button's value = on.

I have spend more than two hours to figure it out. But cannot resolve it. Can anyone please help me to solve the problem?

15
  • name them radio-sl[] instead of radio-sl Commented Apr 20, 2016 at 9:38
  • @Farkie why exactly? That doesn't solve anything. Usually it sends on when you have input=checkbox. Is there any javascript involved before sending the form? Commented Apr 20, 2016 at 9:39
  • It's a huge form and I've some checkboxes after 5 radio buttons. A little script for restricting the maximum # of options also added. Commented Apr 20, 2016 at 9:43
  • What is the name of those checkboxes @musafir Commented Apr 20, 2016 at 9:43
  • Yes, I need some int values fro the checked options. Commented Apr 20, 2016 at 9:44

1 Answer 1

1

Please use below code for radio buttons if input type="radio" then it should give value="" otherwise in value it will show "on" e.g.

<input id="radio-must" class="radio-custom" name="radio-nns" value="absolutely" type="radio" checked>

output = [radio-nns] => on

instead put ( you can see value="1")

<input id="radio-must" class="radio-custom" name="radio-nns" value="absolutely" type="radio" checked value="1">

output =  [radio-nns] =>1
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much brother. Yes, I will change them to some INT value. It will be very helpful if you tell how did you retrieve this array: Array ( [instuctor-name] => [designation] => [university] => [description] => [course-id] => [radio-ge] => 1 [radio-sl] => 1 [radio-ea] => 1 [radio-n] => 1 [radio-feel] => happy [radio-nns] => absolutely [radio-at] => on [radio-tb] => on [grade] => )
if you want to print something you can just put code like (e.g. put code in rating.php starting ) print "<pre>"; // for print in proper format print_r($_POST); //for print post array die; // for stop execution of code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.