2 Replies - 485 Views - Last Post: 01 November 2011 - 07:31 AM Rate Topic: -----

#1 shebby  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 88
  • Joined: 29-June 11

Can i set the time when redirect to the page?

Posted 01 November 2011 - 05:24 AM

  <?php
    mysql_connect("localhost","root") or die(mysql_error());
    mysql_select_db("Regis") or die(mysql_error());



     if (isset($_POST["sub"]))
     {
      $usercheck = $_POST["username"];

       $check = mysql_query("SELECT username FROM registration WHERE username = '$usercheck'") or die(mysql_error());

       $check2 = mysql_num_rows($check);
        //if the name exists it gives an error
     if ($check2 != 0)
     {
      echo("<script LANGUAGE='Javascript'>window.alert('Sorry, the username" . $usercheck . "is already in use.')</SCRIPT>");
       echo ("<script LANGUAGE='Javascript'>window.location = 'registration.php'</script>");


      // print("url=registration.php\");
     }

     }
?>
<html><head></head><body>
 <form action="submit.php" method="post">

 <table border="0"> 

 <tr><td colspan=2><h1>Login</h1></td></tr> 

 <tr><td>Username:</td><td> 

 <input type="text" name="username" maxlength="40"> 

 </td></tr> 

 <tr><td>Password:</td><td> 

 <input type="password" name="pass" maxlength="50"> 

 </td></tr> 

 <tr><td><a href="register.php">Register</a></td>

 <td><input type="submit" name="submit" value="Login">

 </td></tr>

 </table> 

 </form>
 
 </body></html>






my problem is if ($check2 != 0)
{
echo("<script LANGUAGE='Javascript'>window.alert('Sorry, the username" . $usercheck . "is already in use.')</SCRIPT>");
echo ("<script LANGUAGE='Javascript'>window.location = 'registration.php'</script>");



when it redirect to registration.php its seem it take more than 5 seconds to redirect any solution to make it faster????

Is This A Good Question/Topic? 0
  • +

Replies To: Can i set the time when redirect to the page?

#2 shebby  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 88
  • Joined: 29-June 11

Re: Can i set the time when redirect to the page?

Posted 01 November 2011 - 05:32 AM

echo ("<script LANGUAGE='Javascript'>window.location = 'registration.php'</script>"); 
      echo("<script LANGUAGE='Javascript'>window.alert('Sorry, the username" . $usercheck . "is already in use.')</SCRIPT>");





if im change this that would be perfect as the time to redirect that page is exact time but im want that window alert to be appear how to do that?
Was This Post Helpful? 0
  • +
  • -

#3 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 948
  • View blog
  • Posts: 2,357
  • Joined: 15-February 11

Re: Can i set the time when redirect to the page?

Posted 01 November 2011 - 07:31 AM

The page won't redirect when an alert box is present. If you want to control the time period until a redirect you could use the Javascript function setTimeout.
<!DOCTYPE>
<html>
<body>
	<h2>Username already exists</h2>
</body>
<script type="text/javascript">
	setTimeout("window.location = 'http://www.google.com'", 5000);
</script>
</html>



Ultimately I would suggest using AJAX to check if a username exists or not. If the user has to refill the form each time the username exists it's going to deter them from even completing the registration.
With AJAX you'll make a call to your PHP script that checks whether the username exists or not and returns a response to the client (Javascript). You'll determine whether the username exists or not from the response returned and then take the appropriate action.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1