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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.