<?php 
//ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>Cycle Tracks Portal - Validation Page</title>
		<style type="text/css" media="all">@import "images/style.css";
</style>
	<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="rss/" />
	<script language="javascript">
		redirTime = "5000"; 
		redirURL = "index.php"; 
		function redirTimer() {
			self.setTimeout("self.location.href redirURL;",redirTime);
		}
	</script> 
</head>

<body>
<?php
// connection to MySQL server
mysql_connect('localhost','root','');
mysql_select_db('administration');

// *** Validate request to login to this site.
//session_start();

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $loginPassword=$_POST['password']; 
  $MM_redirectLoginSuccess = "validated.php";
  $MM_redirectLoginFailed = "index.php";
  $MM_redirecttoReferrer = true;
  mysql_select_db('administration');
  
	 if(empty($_POST['username']) && empty($_POST['password'])) {
  	 die('<div class="error_up">Both field was blank</div>
		<br><br><div class="footer_padding">
			&copy; Copyright Cycle Tracks <span>®</span></div>
			');
	 }
	 if(empty($_POST['username'])) {
  	 die('<div class="error_up">Username field was blank</div>
		<br><br><div class="footer_padding">
			&copy; Copyright Cycle Tracks <span>®</span></div>
			');
	 }
	 if(empty($_POST['password'])) {
  	 die('<div class="error_up">Password field was blank</div>
		<br><br><div class="footer_padding">
			&copy; Copyright Cycle Tracks <span>®</span></div>
			');
	 }
	
  $loginUsername = get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername);
  $password = get_magic_quotes_gpc() ? $password : addslashes($password);
  $LoginRS_query = "SELECT username, password FROM adminprofile WHERE username='$loginUsername' AND password='$loginPassword'";
  $LoginRS = mysql_query($LoginRS_query) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  
  if ($loginFoundUser) {
    
    echo "<script type='text/javascript'>location.href='$MM_redirectLoginSuccess';</script>";
	}
  else {
    echo "redirTimer()";
}
}
?>

</body>
</html>
<?php 
//ob_end_flush(); 
?>

I know the way i call the function is wrong in line 68, how do i call the js function?

you can do it like what you have done in the 1st statement:

echo "<script type='text/javascript'>"
echo "redirTimer()";
echo "</script>";

not working

maybe include the whole function with variables:

echo  '<script language="javascript">
redirTime = "5000";
redirURL = "index.php";

function redirTimer() {
self.setTimeout("self.location.href redirURL;",redirTime);
}

redirTimer()
</script> ';

not working, can't echo so many thing.

No. Do what he has said in the previous post.
ie.,

echo "<script type='text/javascript'>"
echo "redirTimer()";
echo "</script>";

But, Change this line in your redirTimer function.
This

self.setTimeout("self.location.href redirURL;",redirTime);

To

self.setTimeout("self.location.href=redirURL;",redirTime);

That ll solve your problem.

nice catch Naveen!I haven't seen that.Thanks.

:) Yep!

<?php 
ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>Cycle Tracks Portal - Validation Page</title>
		<style type="text/css" media="all">@import "images/style.css";
</style>
	<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="rss/" />
	
	<script language="javascript">
		redirTime = "5000"; 
		redirURL = "index.php"; 
		function redirTimer() {
			self.setTimeout("self.location.href=redirURL;",redirTime);
	</script>
	
</head>

<body>
<?php
// connection to MySQL server
mysql_connect('localhost','root','');
mysql_select_db('administration');

// *** Validate request to login to this site.
//session_start();

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $loginPassword=$_POST['password']; 
  $MM_redirectLoginSuccess = "validated.php";
  $MM_redirectLoginFailed = "admin.php";
  $MM_redirecttoReferrer = true;
  mysql_select_db('administration');
  
	 if(empty($_POST['username']) && empty($_POST['password'])) {
  	 die('<div class="error_up">Both field was blank</div>
		<br><br><div class="footer_padding">
			&copy; Copyright Cycle Tracks <span>®</span></div>
			');
	 }
	 if(empty($_POST['username'])) {
  	 die('<div class="error_up">Username field was blank</div>
		<br><br><div class="footer_padding">
			&copy; Copyright Cycle Tracks <span>®</span></div>
			');
	 }
	 if(empty($_POST['password'])) {
  	 die('<div class="error_up">Password field was blank</div>
		<br><br><div class="footer_padding">
			&copy; Copyright Cycle Tracks <span>®</span></div>
			');
	 }
	
  $loginUsername = get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername);
  $password = get_magic_quotes_gpc() ? $password : addslashes($password);
  $LoginRS_query = "SELECT username, password FROM adminprofile WHERE username='$loginUsername' AND password='$loginPassword'";
  $LoginRS = mysql_query($LoginRS_query) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  
  if ($loginFoundUser) {
    
    echo "<script type='text/javascript'>location.href='$MM_redirectLoginSuccess';</script>";
	}
  else {
    echo "<script type='text/javascript'>"
	echo "redirTimer()";
	echo "</script>";
}
}
?>

</body>
</html>
<?php 
ob_end_flush(); 
?>

Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';' in D:\xampp\htdocs\cycle\validate.php on line 70

missing ; at line 69. :)

now no more error but it is not redirecting... blank page

Thats because of the delay of 500 seconds :) OR your index.php page is blank.

I've change the 5000 to 50 and my index.php is not a blank page. Still not working?

Its working for me though. Try changing redirectUrl to http://www.yahoo.com and tellme if it works.

Naveen, its not working even if I use http://www.yahoo.com. It doesn't redirect at all because the page url was still validate.php. It shouldn't show validate.php. only validated.php or index.php must be shown. All working fine without the redirection function.

Then its not entering the else part ! echo something in "if" part as well as "else" part. Check the flow.

check already. it just not working......

if ($loginFoundUser) {
    
    echo "<script type='text/javascript'>location.href='$MM_redirectLoginSuccess';</script>";
	}
  else {
	echo ('Refresh: 120; url=http://www.yahoo.com');
    //echo "<script type='text/javascript'>location.href='$MM_redirectLoginFailed';</script>";
}

Even this is not working....

echo something simple.

if($loginFoundUser){ echo "found"; } else { echo "not found"; }

there is no prob in the loop, just the code...

if ($loginFoundUser) {
    
    echo "<script type='text/javascript'>location.href='$MM_redirectLoginSuccess';</script>";
	}
  else {
  
    echo "<script type='text/javascript'>onload='redirTimer()';</script>";
}
}
?>

Line no.7 is not working and no error message was displayed. Pls help

onload wouldn't work. Print what's in $loginFoundUser. Is location.href=MM_redirectLoginSuccess working ?

location.href=MM_redirectLoginSuccess is working. But I want to use the redirection function. Thats why I didn't use the href....

hmm.. okay ! Try this.

echo '<META HTTP-EQUIV="Refresh"
      CONTENT="5; URL=redirect.php">';

This will redirect to redirect.php after 5 seconds.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.