Page 1 of 1

Solved]Radio button help

Posted: Thu Jun 16, 2005 7:32 am
by nhan
i have followed the code in authetication 101 php tutorial, and it is working fine, but i have to add a radio button, these radio buttons will indicate a different of page to be redirected, below is my code, i dont know how to pass the variable of the radio button.... thanks for the help!

any tutorial site would help...

Code: Select all

<?PHP
$db = mysql_connect('xx', 'xx', 'xx') or die("Couldn't connect to the database."); 
mysql_select_db('mydatabase') or die("Couldn't select the database"); 
$result = mysql_query("SELECT count(userId) FROM users WHERE userPass='$_POST[userPass]' AND userName='$_POST[userName]'") or die("Couldn't query the user-database."); 
$num = mysql_result($result, 0); 
if (!$num) { 
echo"
<style type='text/css'>
<!--
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
}
-->
</style>

<table width='367' height='218' border='0' cellpadding='0' cellspacing='0'>
  <tr>
    <td background='login.gif'><table width='367' border='0' cellpadding='0' cellspacing='0'>
      <tr>
        <td><div align='center'>
		<form action='$_SERVER[PHP_SELF]' method='post'>
          <input type='text'  name='userName' value='$_POST[userName]'>
        </div></td>
      </tr>
      <tr>
        <td><div align='center' class='style1'>Username</div></td>
      </tr>
      <tr>
        <td><div align='center'>
          <input type='password' name='userPass'>
        </div></td>
      </tr>
      <tr>
        <td><div align='center' class='style1'>Password</div></td>
      </tr>
    </table>
      <table width='367' border='0' cellspacing='0' cellpadding='0'>
        <tr>
          <td width='71' rowspan='4'>&nbsp;</td>
          <td width='126'>&nbsp;</td>
          <td width='97' rowspan='4'><div align='center'>
            <input type='submit' name='Submit' value='Login'>
          </div></td>
          <td width='73' rowspan='4'>&nbsp;</td>
        </tr>
        <tr>
          <td class='style1'><input name='radiobutton' type='radio' value='tin'>
          Time In </td>
        </tr>
        <tr>
          <td class='style1'><input name='radiobutton' type='radio' value='tout'>
          Time Out </td>
        </tr>
        <tr>
          <td class='style1'><input name='radiobutton' type='radio' value='ot'>
          Overtime</td>
        </tr>
      </table></td>
	  </form>
  </tr>
</table>

";
} else { 

session_start(); 
$id = session_id();

$_SESSION['userName'] = $_POST['userName']; 
$_SESSION['pass'] = $_POST['pass']; 

exit;
} 
?>

Posted: Thu Jun 16, 2005 7:38 am
by Syranide

Code: Select all

$_POST['radiobutton']
?

Posted: Thu Jun 16, 2005 7:41 am
by malcolmboston
the radio button is passed by its name and then its value so for eg.

Code: Select all

&lt;input type=&quote;radio&quote; name=&quote;groupA&quote; value=&quote;area1&quote;&gt;Go To Area 1
&lt;input type=&quote;radio&quote; name=&quote;groupA&quote; value=&quote;area2&quote;&gt;Go To Area 2
&lt;input type=&quote;radio&quote; name=&quote;groupA&quote; value=&quote;area3&quote;&gt;Go To Area 3
then to retrieve and redirect

Code: Select all

if (isset($_POST['groupA']))
{
   if ($_POST['groupA'] == "area1")
   {
      header ("Location: area1.php");
   }
   elseif ($_POST['groupA'] == "area2")
   {
      header ("Location: area2.php");
   }
   elseif ($_POST['groupA'] == "area3")
   {
      header ("Location: area3.php");
   }
   else
   {
      // no valid matches
      print "I dont know where to go";
   }
}
else
{
   // no radio button was submitted
   print "i dont know where to go";
}
hope that helps

Posted: Thu Jun 16, 2005 7:46 am
by nhan
but how do i use the $post[radiobutton] to select a different page, should i use this one??

Code: Select all

switch($_POST&#1111;'radio']){
        case 'tin':
           $timecheck = 'in.php';
           break;
        case 'tout':
           $timecheck = 'out.php';
           break;
        case 'ot':
           $timecheck = 'ot.php';
           break;
        default:
           $timecheck = 'login.php';
     }

header(&quote;Location:$timecheck.php?userName=$_POST&#1111;userName]&sid=$id&quote;);

Posted: Thu Jun 16, 2005 7:49 am
by shiznatix
ya sure why not

Posted: Thu Jun 16, 2005 7:53 am
by nhan
it does not work.... :cry:

Posted: Thu Jun 16, 2005 7:58 am
by Syranide
that's because you aren't inserting it correctly in the header.

Posted: Thu Jun 16, 2005 8:06 am
by nhan
so far, i have tried this one...

Code: Select all

if ($_POST&#1111;'radiobutton'] == $tin){
header(&quote;Location:tin.htm&quote;); 
} 
elseif ($_POST&#1111;'radiobutton'] == $tout){
header(&quote;Location:tout.htm&quote;); 
} 
elseif ($_POST&#1111;'radiobutton'] == $ot){
header(&quote;Location:ot.htm&quote;); 
}
and it seems to work fine.... thanks so much for all the help...

Posted: Thu Jun 16, 2005 8:18 am
by Syranide
I'm guessing
$ot = "ot" ?
etc

Posted: Thu Jun 16, 2005 8:54 am
by nhan
last question, if the data entered was incomplete, for example the radio button was not enabled, what code should i use? so that the page would come back to the login page???

thanks!

Posted: Thu Jun 16, 2005 9:16 am
by malcolmboston
look at my post