Page 1 of 1
session array to save value of radio button
Posted: Wed Apr 18, 2012 12:45 pm
by jamhussain
Code: Select all
<form method="post" action="point.php">
<table bgcolor="#FFCC00" width="40" border="2" cellspacing="10">
<tr><td colspan="20"><input type="radio" name="type" value="1000" />1000 point </tr>
<tr><td colspan="20"><input type="radio" name="type" value="500" />500 point </tr>
<tr><td colspan="2" align="center"><input type="submit" name="submit" id="submit" />
</table>
</form>
<?php
session_start();
if (isset($_POST['Submit'])) {
$_SESSION['a'][0] = $_POST['type'];
if($_SESSION['a'][0]== 1000)
{ $b==1000;}
else
{ $b==500;}
echo"the no is ".$b;
}
?>
please check it that it is right. I want to save the value of radio button in a variable so that I may use it in further calculation.
Re: session array to save value of radio button
Posted: Wed Apr 18, 2012 3:38 pm
by califdon
You cannot use session_start() after you have sent anything to the browser, so you must do that BEFORE any HTML or even any blank lines.
Re: session array to save value of radio button
Posted: Fri Apr 20, 2012 3:34 am
by jamhussain
Please help me that how can improve this code.
session_start() is necessary for communication with session.
How can I save the value of radion button in an variable b so that I may use it in future calucaltion.
thanks.
Re: session array to save value of radio button
Posted: Fri Apr 20, 2012 9:44 am
by x_mutatis_mutandis_x
Swap your php block with the html block (see below)
Code: Select all
<?php
session_start();
if (isset($_POST['Submit'])) {
$_SESSION['a'][0] = $_POST['type'];
if($_SESSION['a'][0]== 1000)
{ $b==1000;}
else
{ $b==500;}
echo"the no is ".$b;
}
?>
<form method="post" action="point.php">
<table bgcolor="#FFCC00" width="40" border="2" cellspacing="10">
<tr><td colspan="20"><input type="radio" name="type" value="1000" />1000 point </tr>
<tr><td colspan="20"><input type="radio" name="type" value="500" />500 point </tr>
<tr><td colspan="2" align="center"><input type="submit" name="submit" id="submit" />
</table>
</form>
Re: session array to save value of radio button
Posted: Fri Apr 20, 2012 9:59 am
by social_experiment
When you equate use a single '=' the double equal sign is used for comparison.
Code: Select all
<?php
session_start();
if (isset($_POST['Submit'])) {
$_SESSION['a'][0] = $_POST['type'];
// comparing here, use of == is correct
if($_SESSION['a'][0]== 1000)
// should be =, not ==
{ $b = 1000;}
else
{ $b = 500;}
echo"the no is ".$b;
}
?>