PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
nhan
Forum Commoner
Posts: 95 Joined: Sun Feb 27, 2005 8:26 pm
Contact:
Post
by nhan » Thu Jun 16, 2005 7:32 am
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'> </td>
<td width='126'> </td>
<td width='97' rowspan='4'><div align='center'>
<input type='submit' name='Submit' value='Login'>
</div></td>
<td width='73' rowspan='4'> </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;
}
?>
Last edited by
nhan on Thu Jun 16, 2005 8:07 am, edited 1 time in total.
Syranide
Forum Contributor
Posts: 281 Joined: Fri May 20, 2005 3:16 pm
Location: Sweden
Post
by Syranide » Thu Jun 16, 2005 7:38 am
malcolmboston
DevNet Resident
Posts: 1826 Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK
Post
by malcolmboston » Thu Jun 16, 2005 7:41 am
the radio button is passed by its name and then its value so for eg.
Code: Select all
<input type="e;radio"e; name="e;groupA"e; value="e;area1"e;>Go To Area 1
<input type="e;radio"e; name="e;groupA"e; value="e;area2"e;>Go To Area 2
<input type="e;radio"e; name="e;groupA"e; value="e;area3"e;>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
nhan
Forum Commoner
Posts: 95 Joined: Sun Feb 27, 2005 8:26 pm
Contact:
Post
by nhan » Thu Jun 16, 2005 7:46 am
but how do i use the $post[radiobutton] to select a different page, should i use this one??
Code: Select all
switch($_POSTї'radio']){
case 'tin':
$timecheck = 'in.php';
break;
case 'tout':
$timecheck = 'out.php';
break;
case 'ot':
$timecheck = 'ot.php';
break;
default:
$timecheck = 'login.php';
}
header("e;Location:$timecheck.php?userName=$_POSTїuserName]&sid=$id"e;);
shiznatix
DevNet Master
Posts: 2745 Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:
Post
by shiznatix » Thu Jun 16, 2005 7:49 am
ya sure why not
nhan
Forum Commoner
Posts: 95 Joined: Sun Feb 27, 2005 8:26 pm
Contact:
Post
by nhan » Thu Jun 16, 2005 7:53 am
it does not work....
Syranide
Forum Contributor
Posts: 281 Joined: Fri May 20, 2005 3:16 pm
Location: Sweden
Post
by Syranide » Thu Jun 16, 2005 7:58 am
that's because you aren't inserting it correctly in the header.
nhan
Forum Commoner
Posts: 95 Joined: Sun Feb 27, 2005 8:26 pm
Contact:
Post
by nhan » Thu Jun 16, 2005 8:06 am
so far, i have tried this one...
Code: Select all
if ($_POSTї'radiobutton'] == $tin){
header("e;Location:tin.htm"e;);
}
elseif ($_POSTї'radiobutton'] == $tout){
header("e;Location:tout.htm"e;);
}
elseif ($_POSTї'radiobutton'] == $ot){
header("e;Location:ot.htm"e;);
}
and it seems to work fine.... thanks so much for all the help...
Syranide
Forum Contributor
Posts: 281 Joined: Fri May 20, 2005 3:16 pm
Location: Sweden
Post
by Syranide » Thu Jun 16, 2005 8:18 am
I'm guessing
$ot = "ot" ?
etc
nhan
Forum Commoner
Posts: 95 Joined: Sun Feb 27, 2005 8:26 pm
Contact:
Post
by nhan » Thu Jun 16, 2005 8:54 am
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!