Jump to content


Photo

Script not working


  • Please log in to reply
7 replies to this topic

#1 Drezard

Drezard
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 15 September 2006 - 09:40 AM

Need alittle help. Cant redirect script. Im kinda new to redirecting scripts.

Heres the error:

Parse error: syntax error, unexpected '<' in C:\Program Files\xampp\htdocs\login_form.php on line 35


Heres the script:


<?php
// initialize a session
session_start();
?>
<html>
<head></head>
<body>

<?php
if (!isset($_SESSION['login']) && !isset($_POST['user'])) {
    // if no data, print the form
?>
    <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
       Username:<input type="text" name="user"><br>
	   Password:<input type="password" name="pass"><br>
        <input type="submit" name="submit">
    </form>
<?php
}
else if (!isset($_SESSION['login'])) {

	include('connect.php');
    // if a session does not exist but the form has been submitted
    // check to see if the form has all required values
    // create a new session
	$user = empty($_POST['user']) ? die ("Please Enter A Username") : mysql_escape_string($_POST['user']);
	$pass = empty($_POST['pass']) ? die ("Please Enter A Password") : mysql_escape_string($_POST['pass']);
	$sql = "SELECT * FROM users WHERE user='$user' AND pass='$pass'";
	$result = mysql_query($sql);
	$count=mysql_num_rows($result);
	
if($count==1){
		
$_SESSION['userinfo'] = $user;	
<meta http-equiv="refresh" content="0;url=login_sucess.php">;
		
		}
		
		if ($count == 0) {
		
		echo "Username or password are incorrect";

		}	
	
}
?>
</body>
</html>

Thanks, Daniel

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 15 September 2006 - 09:51 AM

Change this:
<meta http-equiv="refresh" content="0;url=login_sucess.php">;

To
echo <meta http-equiv="refresh" content="0;url=login_sucess.php">;

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 Drezard

Drezard
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 15 September 2006 - 09:52 AM

I worked out what the problem was but now i got another one:

Parse error: syntax error, unexpected $end in C:\Program Files\xampp\htdocs\login_sucess.php on line 21


Heres the script:

<?php
// initialize a session
session_start();
?>
<html>
<head></head>
<body>

<?php
if (!isset($_SESSION['login']) && !isset($_POST['user'])) {
    // if no data, print the form
?>
    <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
       Username:<input type="text" name="user"><br>
	   Password:<input type="password" name="pass"><br>
        <input type="submit" name="submit">
    </form>
<?php
}
if (!isset($_SESSION['login'])) {

	include('connect.php');
    // if a session does not exist but the form has been submitted
    // check to see if the form has all required values
    // create a new session
	$user = empty($_POST['user']) ? die ("Please Enter A Username") : mysql_escape_string($_POST['user']);
	$pass = empty($_POST['pass']) ? die ("Please Enter A Password") : mysql_escape_string($_POST['pass']);
	$sql = "SELECT * FROM users WHERE user='$user' AND pass='$pass'";
	$result = mysql_query($sql);
	$count=mysql_num_rows($result);
	
	if($count==1){
		
		$_SESSION['userinfo'] = $user;	
		?>
		
		<meta http-equiv="refresh" content="0;url=login_sucess.php">;

		<?php	
	}
		
	if ($count == 0) {
		
		echo "Username or password are incorrect";

		}	
	
}
}
?>
</body>
</html>

- Cheers, Daniel

#4 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 15 September 2006 - 09:58 AM

Try removing one of the } from the end of the file.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#5 Drezard

Drezard
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 16 September 2006 - 02:17 AM

Hello, I have a problem with session_destroy, Im not sure what ive done wrong.

Heres the error:

Warning: session_destroy() [function.session-destroy]: Trying to destroy uninitialized session in C:\Program Files\xampp\htdocs\login_sucess.php on line 4


Heres the script:

<?php
$user = $_SESSION['username'];
setcookie('user', $user, time()+36000*24*365);
session_destroy();
?>

<head>

</head>

<body>

<?php

if (isset($_COOKIE['user'])) {
echo "Login Complete";
}
?>

</body>
</html>

- Thanks, Daniel

#6 markbett

markbett
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 16 September 2006 - 04:10 AM

did you start the session before you tried to destroy it?  you can derstroy somethign that never existed

#7 Drezard

Drezard
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 16 September 2006 - 04:50 AM

But what happens if i started it on a page before?

- Cheers, Daniel

#8 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 16 September 2006 - 06:04 AM

You have to specify session_start() on every page.  Before any code is output to the browser.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users