Jump to content

login script is giving blank page


mariam

Recommended Posts

Hi i am totally new to PHP ( 4 days old to be precise ). i found a very handy tutorial on you tube regarding php login script. i followed it completely however when i enter username and password it redirects me to a blank page (checklogin.php) instead of displaying you have logged in etc (login_success.php). Any idea what may be causing this. I've been googling the solution for 4 days now however but to no avail. anyway here are the codes i used.

 

//..................................................mainlogin.php

 

<html>
<head>
  <title>Main Login Page</title>   
  <style type="text/css">
  #loginform {                      //css styling http://www.w3schools.com/css/default.asp
  border: 2px solid #600;
  background-color: #FFC;
  width: 280px
  }
  #loginform form {
    margin: 5px;
}
label{
display: block;
width: 90px;
float: left;
clear: both;
}
label, input {
margin: bottom: 4px;
}
 </style>
</head>
<body>  
<div id="loginform">
<form method="post" action="checklogin.php" name="form1">
  <label for="username">Username:</label>
  <input type="text" name="myusername" id="username" />
  <label for="password">Password:</label>
  <input type="password" name="mypassword" id="password" />
  <input type="submit" name="submit" value="Login" /> 
  </form>
  </div>
  </body>
  </html>

//.........................................................................checklogin.php

 

<?
$host="localhost"; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name="mariam"; // Database name 
$tbl_name="members"; // Table name
// Connect to server and select databse.
mysql_connect($host, $username, $password)or die("cannot connect"); 
mysql_select_db($db_name)or die("cannot select DB");
// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword'];
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
  session_register("myusername");
  session_register("mypassword"); 
  header("location:login_success.php");
  }
  else {
   echo "Wrong Username or Password";
   }
?>

//..................................................................login_success.php

 

<? 
session_start();
if(!session_is_registered(myusername)){
header("location:mainlogin.php");
}
?>
<html>
<head><title>Welcome</title>
</head>
<body>
<hl>Login Successful</hl>
<p>
<a href="logout.php">Log out!</a></p>
</body>
</html>

//...........................................................................logout.php

 

<? 
session_start();
session_destroy();
?>
<html>
<head><title>Thanks</title>
</head>
<body>
<h1>You are logged out</h1>
<p>
<a href="logout.php">Log out!</a></p>
</body>
</html>

Link to comment
Share on other sites

tutorial on you tube

 

Unfortunately, a lot of the php tutorials posted all over the Internet are out of date, insecure, and non-functional.

 

If you do a 'view source' of the blank checklogin.php page, you will probably see the raw php code.

 

The code you found has many problems, the first being that it is using lazy-way short open tags <? which in the case of the checklogin.php code results in a blank page displaying in the browser because the <? tag is not supported on your server. Change all the <? tags to full opening php tags <?php

Link to comment
Share on other sites

thanks a lot for the prompt responses. i did change <? to <?php now it is displaying this error in checklogin.php.

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\checklogin.php on line 9

cannot connect

i am using XAMPP. Any help would be appreciated.

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.