Jump to content


Photo

What's wrong with this code?


  • Please log in to reply
9 replies to this topic

#1 treilad

treilad
  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts

Posted 18 July 2006 - 05:51 PM

Not sure I should go into detail if it's just a syntax error, but I will if needed.

The error is:

Parse error: parse error, unexpected T_ELSE in C:\Server\wamp\www\project\index.php on line 17


Code:
<?php

if(isset($_COOKIE['ID_my_site']))

{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check )){


  if (!isset($_COOKIE['ID_my_site']))
  {
    header('./logout.php')
 

else
{
  header('./loginpage.php')
}

?>

It doesn't like the 'else', but I don't know why. :-/

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 18 July 2006 - 05:55 PM

You have a missing ; and } after this:
if (!isset($_COOKIE['ID_my_site']))
  {
    header('./logout.php')


it should be:
if (!isset($_COOKIE['ID_my_site']))
{
    header('./logout.php'); // missing
} // missing


#3 ChaosXero

ChaosXero
  • Members
  • PipPipPip
  • Advanced Member
  • 80 posts

Posted 18 July 2006 - 05:56 PM

You're missing a } to end your while loop and your if statement.  You need to close your if and while brackets.

#4 treilad

treilad
  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts

Posted 18 July 2006 - 05:56 PM

Thanks a bunch.  :)

#5 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 18 July 2006 - 05:58 PM

You need a curly right brace before the else. Don't forget semi-colons after each header. And a curly right brace to close off the while loop.

Ask yourself why you're checking the cookie variable within the while loop? also if that's the correct form of use of the header() function?

Please read some more tutorials on basic PHP syntax and use php.net to help yourself learn what header() does.  I think you meant to use include/require.


#6 dptr1988

dptr1988
  • Members
  • PipPipPip
  • Advanced Member
  • 372 posts

Posted 18 July 2006 - 06:00 PM

What about the indenting? It looks like the else should be for the first If statement, which would mean that the first if statment, the while loop, and the second if statement have not been closed.
Need more help with your project? One of the thousands of programmers, web designers or artists at <a href="http://www.rentacode...d_6764522">Rent A Coder</a> would be happy to help.

Disclaimer: Free advice is usually worth what you paid for it. ( or at least when it's coming from me! )

#7 treilad

treilad
  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts

Posted 18 July 2006 - 06:02 PM

I meant to header, because this is just a script to check the credentials of the user. Each page loads it automatically (ideally, anyway. working on that.) to check their credentials, and if they check out, they can view the page.

EDIT:

I said that wrong. I have this at the top of each page. It checks their credentials and if they check out, it does nothing. If the credentials don't match, it removes the cookie because they have a cookie set but their credentials don't match, so they don't keep the cookie. If there isn't a cookie, it boots them from the page to the login page.

Also, now I'm getting this error:

Parse error: parse error, unexpected $end in C:\Server\wamp\www\project\index.php on line 204


204 is the end. Nothing there, so I assume I'm missing something.

#8 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 18 July 2006 - 06:09 PM

You are missing  closing } or ) if you are getting that error. Go through you code making sure your } and ) pair up.

#9 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 18 July 2006 - 06:14 PM

<?php

if(isset($_COOKIE['ID_my_site'])) {

$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];

$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check )) {


  if (!isset($_COOKIE['ID_my_site'])) {
    header('./logout.php')

}else{
 
header('./loginpage.php')
}
}

?>
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#10 treilad

treilad
  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts

Posted 18 July 2006 - 06:22 PM

It didn't like yours, redarrow. :( But I got it to work with wildteens tip.

Also, the code cleared up. No more errors. But I can still visit the page when I'm logged out. I have include('index3.php'); which is the code I just fixed at the top of index.php. Before I make another topic, I'll just put it here and see if there's a simple answer. I need the code to ensure that the page is not visible if the user's credentials do not match up. For some reason it doesn't header me anywhere even when I'm not logged in, as it should. Again, here's my "corrected" code:

<?php

include ('db.php');

if(isset($_COOKIE['ID_my_site']))

{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{


  if (!isset($_COOKIE['ID_my_site']))
  {
    header('./logout.php');
  }
}
}
else
{
  header('./loginpage.php');
}

?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users