473,471 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help with login form

5 New Member
#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.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <head>
  4.  
  5. <?php
  6.  
  7. $users = array('john', 'paul', 'mark', 'luke');
  8.  
  9. $admin = array('dan', 'ify', 'chris', 'jane');
  10.  
  11. if (isset($_POST['submit1'])) {$june = $_POST['paul']; 
  12.  
  13. $members = 'WRONG ID'; }
  14.  
  15. if ($june == $users) {print ('welcome'); }
  16.  
  17. if ($june == $admin) {print ('Welcome back, SuperAdmin'); }  
  18.  
  19. else {print ($members); 
  20.  
  21. ?>
  22.  
  23. </head><body>
  24.  
  25. <form name = 'trial' method = 'post' action = 'trial.php'>
  26.  
  27. <input type = 'TEXT' Name = 'paul' <?php print $june .  ' '; ?> value = 'user' ?>
  28.  
  29. <input type = 'submit' value = 'enter' Name = 'submit1'>
  30.  
  31. </body>
  32.  
  33. </form>
  34.  
  35.  </html>
Oct 7 '14 #1
4 1504
Dormilich
8,658 Recognized Expert Moderator Expert
How do i correct this?
by not comparing a string to an array.
Oct 7 '14 #2
SamDave
5 New Member
I don't understand. Please explain more on it.
Oct 7 '14 #3
Bala Kumaran
30 New Member
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

Expand|Select|Wrap|Line Numbers
  1. $users = array('john', 'paul', 'mark', 'luke');
You should mention the array number. that is

Expand|Select|Wrap|Line Numbers
  1. $users[0]
To get output as paul

Expand|Select|Wrap|Line Numbers
  1. $users[1]
in Your script, in If condition You must mention array not string

Expand|Select|Wrap|Line Numbers
  1. if ($june == $users[0] || $june == $users[1] || $june == $users[2] || $june == $users[3])


Finally,

Answer for your full scripts are below.


Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <head>
  4.  
  5. <?php
  6.  
  7. $users = array('john', 'paul', 'mark', 'luke');
  8.  
  9. $admin = array('dan', 'ify', 'chris', 'jane');
  10.  
  11. if (isset($_POST['submit1'])) 
  12. {
  13.     $june = $_POST['paul']; 
  14.  
  15.     $members = 'WRONG ID';
  16.  
  17.     if ($june == $users[0] || $june == $users[1] || $june == $users[2] || $june == $users[3]) 
  18.     {
  19.         print ('welcome'); 
  20.     }
  21.  
  22.     if ($june == $admin[0] || $june == $admin[1] || $june == $admin[2] || $june == $admin[3]) 
  23.     {
  24.         print ('Welcome back, SuperAdmin'); 
  25.     }  
  26.  
  27.     else {
  28.         print ($members); 
  29.         } 
  30. }
  31. ?>
  32.  
  33. </head><body>
  34.  
  35. <form name = 'trial' method = 'post' action = 'trial.php'>
  36.  
  37. <input type = 'TEXT' Name = 'paul' <?php print $june .  ' '; ?> value = 'user' ?>
  38.  
  39. <input type = 'submit' value = 'enter' Name = 'submit1'>
  40.  
  41. </body>
  42.  
  43. </form>
  44.  
  45.  </html>
Oct 7 '14 #4
Dormilich
8,658 Recognized Expert Moderator Expert
in Your script, in If condition You must mention array not string
Expand|Select|Wrap|Line Numbers
  1. if ($june == $users[0] || $june == $users[1] || $june == $users[2] || $june == $users[3])
or use the more convenient in_array() function.
Oct 7 '14 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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.
5
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?
7
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...
2
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...
15
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...
3
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
3
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...
5
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...
0
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...
0
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...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
1
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...
0
tracyyun
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...
1
isladogs
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.