Jump to content

Radio Button Help


Schlo_50

Recommended Posts

I working on a login system in which a user types a username and password, and then selects a radio button which matches their account type.

 

So if the user attempts a login using department credentials and selects the 'master account' radio button then they shouldn't be able to login, however if the user attempts a login using department credentials and clicks the radio button to confirm they are a department then they will successfully login. (Assuming they have entered the correct details.)

 

Login Form:

<?php
$username = isset($_POST['username']) ? $_POST['username'] : '';
$password = isset($_POST['password']) ? $_POST['password'] : '';
    $selected_radio = $_POST['master'];
$selected_radio2 = $_POST['department'];
?>


<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="loginform">

            <p class="text" align="center"><span class="main"><img src="images/point.png" width="11" height="8" />Username:</span> 
              <input class="text" name="username" type="text"  />
            </p>
            <p class="text" align="center"><span class="main"><img src="images/point.png" width="11" height="8" />Password:</span>
              <input class="text" name="password" type="password" />            
        </p>
            <p class="text" align="center">
            <input type = 'Radio' Name ='client' value= 'master'>Master Site
            <input type = 'Radio' Name ='client' value= 'department'>Sub Site or Department</p>
<p class="text" align="center">
            <input class="text" type="submit" name="submitBtn" value="Login" />
              </p>

</form>

 

Processing Code:

if ($selected_radio = $_POST['master']){
$pfile = fopen("users.txt","r");
    rewind($pfile);

    while (!feof($pfile)) {
        $line = fgets($pfile);
        $tmp = explode('|', $line);
        if ($tmp[0] == $user) {
            // User exists, check password
            if (trim($tmp[1]) == trim(md5($pass))){
            	$validUser= true;
            	$_SESSION['userName'] = $user;
}
            break;
}
}
    fclose($pfile);

}
else {
	$pfile = fopen("departments.txt","r");
    rewind($pfile);

    while (!feof($pfile)) {
        $line = fgets($pfile);
        $tmp = explode('|', $line);
        if ($tmp[0] == $user) {
            // User exists, check password
            if (trim($tmp[1]) == trim(md5($pass))){
            	$validUser= true;
            	$_SESSION['userName'] = $user;
}
            break;
}
}
    fclose($pfile);
}

 

What i want the processing code to try and do is say, "if the use selects to login as a master account search users.txt for a match, else, search departments.txt for a match".

 

Please could i get some help, if you need any questions answered please ask.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/82305-radio-button-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.