brmcdani Posted September 14, 2009 Share Posted September 14, 2009 Iam stuck on my login screen. I have no clue what the deal is. I don't know if I am not connecting to the database properly or what. Here is what I have code wise and the screen shot is what I get when I run it in my browser. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php $con = mysql_connect("localhost", "tutorial", "LsGQmFYsMBjUwvL4"); mysql_select_db("tutorial", $con); $q = "SELECT * FROM `logintable` WHERE user='$usernamefield' AND pass='$passwordfield'"; $logincheck = mysql_query($q, $con) or die(mysql_error($con)); if(!isset($_POST['username']) || !isset($_POST['password'])){ print "No username/password defined";} print_r($logincheck)."<br/>"; print_r($rows); $usernamefield = $_POST['username']; $passwordfield = $_POST['password']; $rows = mysql_fetch_array($logincheck); if ($rows != "") { echo "Welcome please select your lake"; } else { ?> <form id="form1" name="form1" method="post" action=""> <p> <label> User Name: <input type="text" name="username" id="username" /> </label> </p> <p>Password: <label> <input type="text" name="password" id="password" /> </label> </p> <p> <label> <input type="submit" name="submit" id="submit" value="Submit" /> </label> </p> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/174158-solved-login/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 14, 2009 Share Posted September 14, 2009 You are using a .html file not a .php file. By default, php code is only parsed when it is in a .php file. Quote Link to comment https://forums.phpfreaks.com/topic/174158-solved-login/#findComment-918069 Share on other sites More sharing options...
brmcdani Posted September 14, 2009 Author Share Posted September 14, 2009 Ok I saved it as a .php file and now my browser will not even open it? It says webpage cannot be displayed. Quote Link to comment https://forums.phpfreaks.com/topic/174158-solved-login/#findComment-918075 Share on other sites More sharing options...
trq Posted September 14, 2009 Share Posted September 14, 2009 Have you installed and configured php to run on your server? Quote Link to comment https://forums.phpfreaks.com/topic/174158-solved-login/#findComment-918076 Share on other sites More sharing options...
brmcdani Posted September 14, 2009 Author Share Posted September 14, 2009 Yes, I can get my PHP Info up which means it is up and running correct? Quote Link to comment https://forums.phpfreaks.com/topic/174158-solved-login/#findComment-918088 Share on other sites More sharing options...
cbolson Posted September 14, 2009 Share Posted September 14, 2009 Hi, If you have php installed (which you do) but are getting a white screen, this means that you have a php error but the server has it's warnings turned off. Glancing through your code I can see the following errors: line 15. You are missing various brackets. You have this: if(!isset($_POST['username']) || !isset($_POST['password'])){ it should probably be this: if( (!isset($_POST['username']) || (!isset($_POST['password'])) ){ Then, you open an "if" but don't close it: if ($rows != "") { echo "Welcome please select your lake"; } else { ?> <form id="form1" name="form1" method="post" action=""> <p> <label> User Name: <input type="text" name="username" id="username" /> </label> </p> <p>Password: <label> <input type="text" name="password" id="password" /> </label> </p> <p> <label> <input type="submit" name="submit" id="submit" value="Submit" /> </label> </p> </form> After that closing form tag you need to open php again and close the "if": </form> <?php } ?> That should help you on your way. Chris Quote Link to comment https://forums.phpfreaks.com/topic/174158-solved-login/#findComment-918130 Share on other sites More sharing options...
Adam Posted September 14, 2009 Share Posted September 14, 2009 You have this: if(!isset($_POST['username']) || !isset($_POST['password'])){ it should probably be this: if( (!isset($_POST['username']) || (!isset($_POST['password'])) ){ Actually you don't need to add in extra brackets like that. His was fine, yours has a syntax error. Also to add though, you're trying to use a variable before you've declared it. The $usernamefield and $passwordfield variables need to be moved before the query. You should also looking securing those inputs from XSS attacks. 1 more thing as well, to determine if the query successfully returned a matching row, use mysql_num_rows. Quote Link to comment https://forums.phpfreaks.com/topic/174158-solved-login/#findComment-918132 Share on other sites More sharing options...
cbolson Posted September 14, 2009 Share Posted September 14, 2009 Actually you don't need to add in extra brackets like that. His was fine, yours has a syntax error. Opps, I missed a closing bracket in the middle there, not very helpful of me sorry. Of course you are right about not needing the extra brackets, I should have mentioned them as they aren't part of the problem. Other than what you suggest about the correct way to check if the query has returned a result, I still think that the main problem here is the lack of the closing brackets on the "if" clause. Sorry if I have caused any confusion, trying to do too many things at once, I need to step away from the keyboard for a while Chris Quote Link to comment https://forums.phpfreaks.com/topic/174158-solved-login/#findComment-918139 Share on other sites More sharing options...
Adam Posted September 14, 2009 Share Posted September 14, 2009 Heh no I agree about the missing brace, was just adding some extra thoughts in. Quote Link to comment https://forums.phpfreaks.com/topic/174158-solved-login/#findComment-918143 Share on other sites More sharing options...
brmcdani Posted September 14, 2009 Author Share Posted September 14, 2009 I just started over and redid my entire scripts again and it worked. Some dumb error in there connecting to the database I am sure! Stress Relief!!! Quote Link to comment https://forums.phpfreaks.com/topic/174158-solved-login/#findComment-918492 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.