#php Am Trying to create a form with array(); in which users can log in . The problem am having is that when ever i call the array(); i.e $users into
function, it dislays wrong members ID. How do i correct this? Please a detailed analysis and if possible a sample code would be appreciated. - <html>
-
-
<head>
-
-
<?php
-
-
$users = array('john', 'paul', 'mark', 'luke');
-
-
$admin = array('dan', 'ify', 'chris', 'jane');
-
-
if (isset($_POST['submit1'])) {$june = $_POST['paul'];
-
-
$members = 'WRONG ID'; }
-
-
if ($june == $users) {print ('welcome'); }
-
-
if ($june == $admin) {print ('Welcome back, SuperAdmin'); }
-
-
else {print ($members);
-
}
-
-
?>
-
-
</head><body>
-
-
<form name = 'trial' method = 'post' action = 'trial.php'>
-
-
<input type = 'TEXT' Name = 'paul' <?php print $june . ' '; ?> value = 'user' ?>
-
-
<input type = 'submit' value = 'enter' Name = 'submit1'>
-
-
</body>
-
-
</form>
-
-
</html>
4 1504 Dormilich 8,658
Recognized Expert Moderator Expert
How do i correct this?
by not comparing a string to an array.
I don't understand. Please explain more on it.
Hello SamDave,
Your Scripts are well. But, You've forgot to change the string into array.
For example, If you wanna get the name 'john' from the below array - $users = array('john', 'paul', 'mark', 'luke');
You should mention the array number. that is
To get output as paul
in Your script, in If condition You must mention array not string - if ($june == $users[0] || $june == $users[1] || $june == $users[2] || $june == $users[3])
Finally,
Answer for your full scripts are below. - <html>
-
-
<head>
-
-
<?php
-
-
$users = array('john', 'paul', 'mark', 'luke');
-
-
$admin = array('dan', 'ify', 'chris', 'jane');
-
-
if (isset($_POST['submit1']))
-
{
-
$june = $_POST['paul'];
-
-
$members = 'WRONG ID';
-
-
if ($june == $users[0] || $june == $users[1] || $june == $users[2] || $june == $users[3])
-
{
-
print ('welcome');
-
}
-
-
if ($june == $admin[0] || $june == $admin[1] || $june == $admin[2] || $june == $admin[3])
-
{
-
print ('Welcome back, SuperAdmin');
-
}
-
-
else {
-
print ($members);
-
}
-
}
-
?>
-
-
</head><body>
-
-
<form name = 'trial' method = 'post' action = 'trial.php'>
-
-
<input type = 'TEXT' Name = 'paul' <?php print $june . ' '; ?> value = 'user' ?>
-
-
<input type = 'submit' value = 'enter' Name = 'submit1'>
-
-
</body>
-
-
</form>
-
-
</html>
Dormilich 8,658
Recognized Expert Moderator Expert
in Your script, in If condition You must mention array not string - if ($june == $users[0] || $june == $users[1] || $june == $users[2] || $june == $users[3])
or use the more convenient in_array() function.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: John Wolrehammer |
last post by:
After the user login in i want to close the login form. I
can close it but it also closes the whole application.
Can anyone help.
|
by: JPSutor |
last post by:
I have a login form, that if successfully answered, launches another
form. The problem is that the login form remains even after I show the
main form. How do I get rid of the login form?
|
by: Grant Merwitz |
last post by:
Hi
I am trying to get the enter key to submit my login form
The login form is currently in a control on the page and uses an
asp:imagebutton as it's login button.
If a user presses enter...
|
by: pv |
last post by:
Hi everyone,
I need help with following scenario, please:
Users are accessing same web server from intranet (users previously
authenticated in Active Dir) and from extranet (common public...
|
by: carr4895 |
last post by:
Hello.
I was wondering if someone could help me too with a login form. Upon
startup, I have to display a password screen and it should accept a
user name and password. User name can be anything...
|
by: Agnes |
last post by:
My login form will call a main form with menu
in my button_OK click event
>dim frmMain as new mainform
>frmMain.show()
>Me.dispose()
The login form didn't close by itself, Please help.. Thanks
|
by: Bob |
last post by:
I haver a user login form (winforms app using vs2005 in VB.NET). After
succesfull validayion of user I want to open a first form and close the
loging form that was used, If I write
If...
|
by: Ronald S. Cook |
last post by:
It's been longer that I remember since writing windows (not web) apps.
1) I want to load a main form
2) User clicks login button which brings up login form (on top of main form)
3) Upon...
|
by: Rinoa |
last post by:
I'm developing a program with a login form. I want the login in form to be the first form that loads, and I want it to close itself when the main CP loads. However, when I set frmLogIn as the startup...
|
by: sandari |
last post by:
The following code (web.config in Visual Studio 2005) is supposed to redirect a user to the appropriate Form depending on their role.
However, regardless of the user's role, the only page...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |