3raser Posted July 23, 2010 Share Posted July 23, 2010 After I click register on the register form, it takes me back to the home page. Why doesn't it go to the next page, that tells me my account was created? This is all on one file. <html> <title>Login Form</title> <head> <link href="style2.css" rel="stylesheet" type="text/css"> <div class="header"> <center><h1><font color="black" size=10></font></h1></center> </div> </head> <body> <div class="container"> <div class="leftnav"> <h2><u><font color="black"size=3>Site Navigation</font></u></h2> <br> <center><a href="index.html">Log In</a></center> <br> <center><a href="index2.html">Register</a></center> <br> <center><a href="index3.html">Forums</a></center> <br> <center><a href="index4.html">Contact Me</a></center> </div> <div class="rightnav"> <u><font color="black">Other Websites</font></u> <br><br/> <center><a href="http://www.halocharts.com/">Halocharts</a></center> <br> <center><a href="http://www.halotracker.com/">HaloTracker</a></center> <br> <center><a href="http://www.bungie.net/">Bungie</a></center> <br> <center><a href="http://www.halotags.com/">HaloTags</a></center> </div> <div class="body"> <?php $session = $_SESSION['user']; $page = $_GET['page']; $page_p = $_POST['page']; $action = $_POST['action']; if($page==0) { echo "Welcome to the site. You can <a href='home.php?page=1'>Login</a> or <a href='home.php?page=2'>Register</a>!"; } elseif($page==1 || $page_p==1) { if($action==1) { //login proccess } elseif($action==0) { if(!$session) { echo '<form action="home.php" method="POST"> <input type="hidden" name="page" value="1"><input type="hidden" name="action" value="1"> <center><font color="#8DDF5D" size=10>Log In</font></center> <br> <br> <center><u><font color="orange" size=5>Username</font></u></center> <br> <center><input type="textbox" name="Username" value="Username"></center> <br> <center><u><font color="orange" size=5>Password</font></u></center> <br> <center><input type="password" name="password" value="password"></center> <center><button name="button">Login</button></center> <br> <center><a href="http://www.youtube.com/user/crazyeagle567"><img src="images/youtube.jpg" height="100" width="250"></a></center> <center><font color="black"> </font></center> </form>'; } } else { echo "Welcome to the site ". $session .". I hope you enjoy your stay here."; } } elseif($page==2 || $page_p==2) { if($action==1) { if(!$username || !$password) { echo "Sorry, one of the fields aren't filled out."; } else { $SQL = mysql_query("SELECT COUNT(username) FROM users WHERE username='$username'"); $row = mysql_fetch_array($SQL); $username = $_POST['username']; $password = $_POST['password']; $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); if($row['COUNT(username)'] < 0) { echo "That username already exists."; } else { $ip = $_SERVER['REMOTE_ADDR']; $date = date("M-D-y"); mysql_insert("INSERT INTO users VALUES ('', '$username', '$password', '$ip', '$date')"); echo "You have been registered successfully, ". $username ."."; } } } else { echo '<form action="home.php" method="POST"> <input type="hidden" name="page" value="2"><input type="hidden" name="action" value="1"> <center><font color="#8DDF5D" size=10>Register</font></center> <br> <br> <center><u><font color="orange" size=5>Username</font></u></center> <br> <center><input type="textbox" name="Username" value="Username"></center> <br> <center><u><font color="orange" size=5>Password</font></u></center> <br> <center><input type="password" name="password" value="password"></center> <center><button name="button">Register</button></center> </form>'; } } ?> </div> <div class="footer"> <center>Copyright 2010</center> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/208711-why-doesnt-it-go-to-the-next-step/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 23, 2010 Share Posted July 23, 2010 Php, despite being a loosely typed language, got loose comparisons with the number zero wrong. The external values you receive from post/get/cookies are all strings by definition. When you compare them with a number using a loose comparison (==, <, >) any string is equal to the number zero and your code is always matching the if($page==0) test. You need to put the numbers on the right-hand side of all of your comparisons (at least for the zero) inside of single-quotes if($page=='0') Quote Link to comment https://forums.phpfreaks.com/topic/208711-why-doesnt-it-go-to-the-next-step/#findComment-1090397 Share on other sites More sharing options...
3raser Posted July 23, 2010 Author Share Posted July 23, 2010 Php, despite being a loosely typed language, got loose comparisons with the number zero wrong. The external values you receive from post/get/cookies are all strings by definition. When you compare them with a number using a loose comparison (==, <, >) any string is equal to the number zero and your code is always matching the if($page==0) test. You need to put the numbers on the right-hand side of all of your comparisons (at least for the zero) inside of single-quotes if($page=='0') I changed it to !$page, and it works just as fine. I changed everything else to if($page=='#') - But its still the same problem. Quote Link to comment https://forums.phpfreaks.com/topic/208711-why-doesnt-it-go-to-the-next-step/#findComment-1090400 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.