GameYin Posted March 28, 2008 Share Posted March 28, 2008 http://validator.w3.org/check?uri=http%3A%2F%2Fwww.gameyin.com%2Findex.php&charset=%28detect+automatically%29&doctype=Inline&ss=1&group=1&No200=1&st=1#line-277 Why is my page not validating? For those of you who helped on my miniproject of the login..thank you... Here is the snippet that is causing me headaches... <?php if (!isset($_COOKIE['loggedin'])) die("<p>You are not logged in!<a href=\"login.html\">log in</a></p>"); $mysite_username = $HTTP_COOKIE_VARS["mysite_username"]; echo "<p>You are logged in as $mysite_username.</p>"; ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
GameYin Posted March 28, 2008 Author Share Posted March 28, 2008 Also, for you PHP gurus, why is it doing the thing near the top of my nav... Here is the code for that. <div class="tmenu"> <b><a class="add" href="index.php">Home</a></b> <a href="store/index.html">Store</a> <?php $mysite_username = $_COOKIE['mysite_username']; if (!isset($_COOKIE['loggedin'])) { echo "<a href=\"register.html\">Register</a> <a href=\"login.html\">Login</a>"; } else { echo "<a href=\"logout.php\">Logout</a> <a href=\"usercp/index.html\">UserCP</a>"; } ?> <a href="arcade/index.html">Arcade</a> <a href="tutorials/index.html">Tutorials</a> <a href="forums/index.html">Forums</a> <a href="webhosting/index.html">Web Hosting</a> </div> Is it because, in my index.php, I'm using HTTP_COOKIE_VARS? <?php if (!isset($_COOKIE['loggedin'])) die("<p>You are not logged in!<a href=\"login.html\">log in</a></p>"); $mysite_username = $HTTP_COOKIE_VARS["mysite_username"]; echo "<p>You are logged in as $mysite_username.</p>"; ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 28, 2008 Share Posted March 28, 2008 It is not valid because the page doesn't have the closing BODY and HTML tags. Try using this instead: <?php $authed = isset($_COOKIE['loggedin']); if ($authed){ echo "<p>You are logged in as $mysite_username.</p>"; $mysite_username = $HTTP_COOKIE_VARS["mysite_username"]; }else{ echo "<p>You are not logged in!<a href=\"login.html\">log in</a></p>"; } ?> If there is other stuff on the page that you want hidden, just put it inside an if($authed){} statement, and only logged in people will see it Quote Link to comment Share on other sites More sharing options...
GameYin Posted March 28, 2008 Author Share Posted March 28, 2008 Yes my page has closing body and html tags. Thanks for the code. It works. Many thanks. JW, what did I do wrong? I stared at the code for an hour before posting here.. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 28, 2008 Share Posted March 28, 2008 If you do a die("some text") it's just like doing print "some text";exit; So, after printing the string it hauls the script. So even if you have close body/html tags later on they won't be printed. Easy way to see it is to just do a view source on the generated page. Quote Link to comment Share on other sites More sharing options...
GameYin Posted March 28, 2008 Author Share Posted March 28, 2008 www.gameyin.com/register.html Look at the top nav bar...help? Thanks for the advice rhodesa <div class="tmenu"> <b><a class="add" href="index.php">Home</a></b> <a href="store/index.html">Store</a> <?php $mysite_username = $_COOKIE['mysite_username']; if (!isset($_COOKIE['loggedin'])) { echo "<a href=\"register.html\">Register</a> <a href=\"login.html\">Login</a>"; } else { echo "<a href=\"logout.php\">Logout</a> <a href=\"usercp/index.html\">UserCP</a>"; } ?> I have an instance of HTTP_COOKIE_VARS in my website somewhere, would that be affecting this? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 28, 2008 Share Posted March 28, 2008 Normally, Apache is not configured to process .html files as PHP You either need to configure Apache to process .html files as PHP, or (preferred) rename it to register.php Quote Link to comment Share on other sites More sharing options...
GameYin Posted March 28, 2008 Author Share Posted March 28, 2008 Sigh, Ok thanks. Quote Link to comment Share on other sites More sharing options...
GameYin Posted March 29, 2008 Author Share Posted March 29, 2008 I just renamed some stuff..www.gameyin.com/registeraction.php Why is this not validating http://validator.w3.org/check?uri=http%3A%2F%2Fwww.gameyin.com%2Fregisteraction.php&charset=%28detect+automatically%29&doctype=Inline&ss=1&group=1&No200=1&st=1#line-269 Here's the PHP code along w/ the line of error if ($num_rows != 0) { echo "<p id=\"register\">Sorry, there the username $user is already taken.<a href=\"register.html\">Try again</a></p>"; exit; } else { // insert the data $insert = mysql_query("insert into $tbl_name values ('NULL', '".$_POST['username']."', '".$_POST['password']."')") or die("<h3><p>Could not insert data because</p></h3> ".mysql_error()); // print a success message echo "<p id=\"register\">Your user account has been created! Now you can <a href=\"login.php\">Log in</a></p>"; } ?> Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 29, 2008 Share Posted March 29, 2008 Same reason as before: If you do a die("some text") it's just like doing print "some text";exit; So, after printing the string it hauls the script. So even if you have close body/html tags later on they won't be printed. Easy way to see it is to just do a view source on the generated page. Quote Link to comment Share on other sites More sharing options...
GameYin Posted March 29, 2008 Author Share Posted March 29, 2008 So, for changing... if ($num_rows != 0) { echo "<p id=\"register\">Sorry, there the username $user is already taken.<a href=\"register.html\">Try again</a></p>"; exit; } else { // insert the data $insert = mysql_query("insert into $tbl_name values ('NULL', '".$_POST['username']."', '".$_POST['password']."')") or die("<h3><p>Could not insert data because</p></h3> ".mysql_error()); // print a success message echo "<p id=\"register\">Your user account has been created! Now you can <a href=\"login.php\">Log in</a></p>"; } ?> Would be...? (Sorry for my ignorance...I am still new ) To Quote Link to comment Share on other sites More sharing options...
GameYin Posted March 29, 2008 Author Share Posted March 29, 2008 Anyone??? Quote Link to comment Share on other sites More sharing options...
GameYin Posted March 29, 2008 Author Share Posted March 29, 2008 Got it working ;D ;D ;D ;D I used this code instead $num_rows = mysql_num_rows($qry); if ($num_rows != 0) { echo "<p id=\"register\">Sorry, there the username <b>$user</b> is already taken. <a href=\"register.php\">Try again</a></p>"; } else { $insert = mysql_query("insert into $tbl_name values ('NULL', '".$_POST['username']."', '".$_POST['password']."')"); echo "<p id=\"register\">Your user account has been created! Now you can <a href=\"login.php\">Log in</a></p>"; } ?> 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.