473,404 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

login page php and javascript

20
I'm working on a login page by user level. but it didnt seems to work. it doesnt redirect and leave a blank page.

index.php (where the form at)

Expand|Select|Wrap|Line Numbers
  1. <form class="login" action="login.php" method="post">
  2. &nbsp;&nbsp;<b>Username:</b>&nbsp;<input type="text" name="username" id="username"/>&nbsp;&nbsp;
  3. <b>Password:</b>&nbsp;<input type="password" name="password" id="password"/>
  4. &nbsp;<input type="submit" value="login" onClick="return check()"/>
  5. </form>
login.php

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.  
  3.     include('config.php');
  4.     session_start();
  5.  
  6.  
  7. if(isset($_POST['submit'])) {
  8.  
  9.     $username = $_POST['username'];
  10.     $password = $_POST['password'];
  11.  
  12.         $username = mysql_real_escape_string($username);    
  13.         $password = mysql_real_escape_string($password);
  14.  
  15.         $sql = mysql_query("SELECT * FROM admin WHERE username='$username' and password='$password'");
  16.         $result = mysql_fetch_array($sql);
  17.  
  18.         $username=$result['username'];
  19.         $adminID=$result['adminID'];
  20.         $userLevel=$result['userLevel'];
  21.  
  22.         $_SESSION['adminID']=$adminID;
  23.         $_SESSION['userLevel']=$userLevel;
  24.         $_SESSION['username']=$username;
  25.         $_SESSION['password']=$password;
  26.  
  27.         if($userLevel=="1")
  28.         {
  29.         ?>
  30.         <script languange='JavaScript'>
  31.         alert("Welcome <?php echo "$username" ?> to Admin Page! ");
  32.  
  33.         <?php
  34.  
  35.          $sql = "UPDATE admin SET status = 'AKTIF' where username = '$username' ";
  36.          $result = mysql_query($sql) or die('Cannot UPDATE.'.mysql_error());
  37.  
  38.          echo"<meta http-equiv='refresh' content='0; URL=admin.php'>";
  39.         }
  40.  
  41.         else if($userLevel=="0")
  42.         {
  43.         ?>
  44.         <script languange='JavaScript'>
  45.         alert("Welcome <?php echo "$username" ?> to User page! ");
  46.  
  47.         <?php
  48.  
  49.         $sql = "UPDATE admin SET status = 'AKTIF' where username = '$username' ";
  50.         $result = mysql_query($sql) or die('Cannot UPDATE.'.mysql_error());
  51.  
  52.         echo"<meta http-equiv='refresh' content='0; URL=user.php'>";
  53.         }
  54.         else
  55.         {
  56.             echo "<script>";
  57.             echo "alert(Invalid username or password.')";
  58.             echo "</script>";
  59.         }
  60.  
  61.     }
  62. ?>
did I miss something? :/
Apr 2 '14 #1
1 1351
koharu
10
Since you have no validation, one can assume that there could be an issue with your SQL Query, or the data being sent to your SQL Query. Turn on Error Reporting (error_reporting('E_ALL'); and ensure you have proper levels of validation applied to your query to ensure your query is returning data.

Also, your page will only display if something is posted to it, if nothing is posted to the page, it will display a blank page.
May 5 '14 #2

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

Similar topics

10
by: amit.purohit | last post by:
hi, I have a very strange problem on my login Page. the Page was working fine a few days back, but now does not generate post back events for controls. this login page uses form based...
12
by: Stanley | last post by:
Hi, I'd like to write a HTML page which can help me directly log in my Yahoo!mail or Gmail account without typing user name and password. Basically, I want to set up a link, click it and pop up...
12
by: ACaunter | last post by:
Hi all, I was wondering how i could write some code which would automatically open the Login Page once the session has expired? -- AdamPC@hotmail.com
0
by: ABC | last post by:
There have ASP.NET application using form authorization. Some buttons of the page will open a new modal windows using javascript "Window,ShowModalDialog". As users logoned the application when...
1
by: ABC | last post by:
After the application user login, when I click the master page button, it popup window using javascript's window.showModalDialog function as: Response.Write("<script...
3
by: webmaniac | last post by:
Hi, Does anyone know, How to create a Login Page & read the username & password from xml file. Like my XML file is going to store the username & password. & when user is going to put the...
9
by: adweaver | last post by:
Hello All, I'm new to the world of php. I've just had a site designed for me by a company, and I'm now trying to manage and grow it, so it will suit my needs. The site was built in a folder...
21
by: tvnaidu | last post by:
This is the Java script I am using fo rlogin page, but cursor not pointing to login box, any idea how can I point cursor to login box when this page loaded?. here admin login take to control page and...
2
by: Nicholas25 | last post by:
How do I create a login page a SECURED one? I found this but not a secured login. Help me out! The Username are: Simon,Visitor and Tom. Password are also the username. But you can change it the BOLD...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.