Jump to content

Why not valid...?


GameYin

Recommended Posts

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>

 

 

Link to comment
https://forums.phpfreaks.com/topic/98357-why-not-valid/
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/98357-why-not-valid/#findComment-503370
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/98357-why-not-valid/#findComment-503374
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/98357-why-not-valid/#findComment-503400
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/98357-why-not-valid/#findComment-503409
Share on other sites

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>"; 
}
?>

Link to comment
https://forums.phpfreaks.com/topic/98357-why-not-valid/#findComment-503715
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/98357-why-not-valid/#findComment-504041
Share on other sites

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 ;D)

 

To

Link to comment
https://forums.phpfreaks.com/topic/98357-why-not-valid/#findComment-504254
Share on other sites

Got it working  ;D ;D ;D ;D ;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>"; 
}
?>

Link to comment
https://forums.phpfreaks.com/topic/98357-why-not-valid/#findComment-504315
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.