mariam Posted May 17, 2011 Share Posted May 17, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/236618-login-script-is-giving-blank-page/ Share on other sites More sharing options...
JonnoTheDev Posted May 17, 2011 Share Posted May 17, 2011 An error! Find out from your webhost how to display php errors. Usually a .htaccess will do the trick with php_flag display_errors on Quote Link to comment https://forums.phpfreaks.com/topic/236618-login-script-is-giving-blank-page/#findComment-1216420 Share on other sites More sharing options...
ambbarees Posted May 17, 2011 Share Posted May 17, 2011 I would recommend this script.http://php-login-script.com/.Download it and learn from executing it. Quote Link to comment https://forums.phpfreaks.com/topic/236618-login-script-is-giving-blank-page/#findComment-1216424 Share on other sites More sharing options...
PFMaBiSmAd Posted May 17, 2011 Share Posted May 17, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/236618-login-script-is-giving-blank-page/#findComment-1216426 Share on other sites More sharing options...
mariam Posted May 17, 2011 Author Share Posted May 17, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/236618-login-script-is-giving-blank-page/#findComment-1216559 Share on other sites More sharing options...
PFMaBiSmAd Posted May 17, 2011 Share Posted May 17, 2011 You have to put the correct username and password for your database into the following two lines - $username=""; // Mysql username $password=""; // Mysql password Quote Link to comment https://forums.phpfreaks.com/topic/236618-login-script-is-giving-blank-page/#findComment-1216564 Share on other sites More sharing options...
mariam Posted May 18, 2011 Author Share Posted May 18, 2011 Thanks you sooo much . All i did was $username = "root"; $password = ""; and it has started working. Thanks all of you for the help. Quote Link to comment https://forums.phpfreaks.com/topic/236618-login-script-is-giving-blank-page/#findComment-1216879 Share on other sites More sharing options...
JonnoTheDev Posted May 18, 2011 Share Posted May 18, 2011 That means you have not set a root password. You better get that done quick. Quote Link to comment https://forums.phpfreaks.com/topic/236618-login-script-is-giving-blank-page/#findComment-1216892 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.