conan318 Posted August 4, 2011 Share Posted August 4, 2011 does not redirected to login_success.php also does not throw up wrong username or password message. gives no errors and all i get is a blank screen on the checklogin.php. is there something im missing? login.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <? session_start(); require "database.php"; ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; " /> <title>Untitled Document</title> <link href="css/main.css" rel="stylesheet" type="text/css" /> </head> <body> <div class="content"> <div class="header"> <img src="banner.png" /> </div> <div class="login"> <form name="form1" method="POST" action="checklogin.php"> Username <input name="myusername" type="text" id="myusername"> <br /> Password <input name="mypassword" type="password" id="mypassword"> <br /> <input type="submit" name="Submit" value="Login"> </form> </div> </div> </body> </html> checklogin.php <? mysql_connect("localhost", "", "")or die("cannot connect"); mysql_select_db("main")or die("cannot select DB"); // username and password sent from form $myusername=$_POST['myusername']; $mypassword=md5($_POST["mypassword"]); // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM main.users 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["myusername"] = $myusername; //copy $myusername to $_SESSION['myusername'] $_SESSION["mypassword"] = $mypassword; //copy $mypassword to $_SESSION['mypassword'] $_SESSION["country"] = $country; $_SESSION["state"] = $state; header("location: login_success.php"); else { echo "Wrong Username or Password"; } } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted August 4, 2011 Share Posted August 4, 2011 Have you got error reporting enabled? Speaking of handling errors. Your not bothering to check your query even works before using it's result. Quote Link to comment Share on other sites More sharing options...
conan318 Posted August 4, 2011 Author Share Posted August 4, 2011 i believe my error handling is on has been getting errors all night lol how do i check if its on? Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 4, 2011 Share Posted August 4, 2011 you have 2 closing bracket after your ELSE statement, and none before... you have this: if(){ ... else{ ... } } you should have: if(){ ... }else{ ... } Quote Link to comment Share on other sites More sharing options...
conan318 Posted August 4, 2011 Author Share Posted August 4, 2011 still just getting a blank screen also noticed i had $count=mysql_num_rows($result); Have you got error reporting enabled? Speaking of handling errors. Your not bothering to check your query even works before using it's result. do i use the or die to check if the query worked? <? mysql_connect("localhost", "admin", "admin")or die("cannot connect"); mysql_select_db("main")or die("cannot select DB"); // username and password sent from form $myusername=$_POST['myusername']; $mypassword=md5($_POST["mypassword"]); // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT username,password FROM main.users 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["myusername"] = $myusername; //copy $myusername to $_SESSION['myusername'] $_SESSION["mypassword"] = $mypassword; //copy $mypassword to $_SESSION['mypassword'] $_SESSION["country"] = $country; $_SESSION["state"] = $state; } header("location: login_success.php"); else { echo "Wrong Username or Password"; } ?> Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 4, 2011 Share Posted August 4, 2011 still the same problem... where does the ELSE come from? change this: if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" $_SESSION["myusername"] = $myusername; //copy $myusername to $_SESSION['myusername'] $_SESSION["mypassword"] = $mypassword; //copy $mypassword to $_SESSION['mypassword'] $_SESSION["country"] = $country; $_SESSION["state"] = $state; } header("location: login_success.php"); else { echo "Wrong Username or Password"; } to this: if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" $_SESSION["myusername"] = $myusername; //copy $myusername to $_SESSION['myusername'] $_SESSION["mypassword"] = $mypassword; //copy $mypassword to $_SESSION['mypassword'] $_SESSION["country"] = $country; $_SESSION["state"] = $state; header("location: login_success.php"); }else { echo "Wrong Username or Password"; } Quote Link to comment Share on other sites More sharing options...
trq Posted August 4, 2011 Share Posted August 4, 2011 You should be getting a fatal error. Your call to header() is in between the } and else, this is invalid. Quote Link to comment Share on other sites More sharing options...
TOA Posted August 4, 2011 Share Posted August 4, 2011 You should be getting a fatal error. Your call to header() is in between the } and else, this is invalid. Beat me to it Quote Link to comment Share on other sites More sharing options...
conan318 Posted August 4, 2011 Author Share Posted August 4, 2011 still just getting a blank page.. i just tested one of other pages and manged to get an error to throw up the error handling is on. but im still getting a blank a page with no errors. is there something wrong with my query maybe... the database name is main and the table is called users with a username and password field in the table. if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" $_SESSION["myusername"] = $myusername; //copy $myusername to $_SESSION['myusername'] $_SESSION["mypassword"] = $mypassword; //copy $mypassword to $_SESSION['mypassword'] $_SESSION["country"] = $country; $_SESSION["state"] = $state; header("location: login_success.php"); // is the call header meant to be here like this? looks right to me }else { echo "Wrong Username or Password"; } Quote Link to comment Share on other sites More sharing options...
conan318 Posted August 4, 2011 Author Share Posted August 4, 2011 just had a thought im using short tags do they work when running a wamp server? Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 4, 2011 Share Posted August 4, 2011 put session_start(); at top of file. Quote Link to comment Share on other sites More sharing options...
conan318 Posted August 4, 2011 Author Share Posted August 4, 2011 thanks again guys the short tag <? was causing the problem all is well again Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 4, 2011 Share Posted August 4, 2011 you're still going to need session_start(); in that file. Quote Link to comment Share on other sites More sharing options...
conan318 Posted August 4, 2011 Author Share Posted August 4, 2011 you're still going to need session_start(); in that file. thanks mate added session start Quote Link to comment 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.