Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 9th, 2012  |  syntax: None  |  size: 1.57 KB  |  hits: 27  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. If else statement that redirects to another page
  2. <?php
  3. $con = mysql_connect("localhost","site","xxxxxxxx");
  4. if (!$con)
  5.    {
  6.    die('Could not connect: ' . mysql_error());
  7.    }
  8.  
  9. mysql_select_db("site", $con);
  10.  
  11. $query = "SELECT * FROM Members WHERE firstname='$_POST[firstname]' and surname='$_POST[surname]'";  
  12. $result = mysql_query($query);
  13.  
  14. if ($result==$something)
  15.    {
  16.    echo "great success"; //user continues loading page
  17.    }
  18. else
  19.    {
  20.    echo "fail"; //user is redirected to sign up page
  21.    }
  22. ?>
  23.        
  24. <?php
  25.  
  26. $con = mysql_connect( "localhost", "site", "xxxxxxxx" );
  27. if ( !$con ) {
  28.     die('Could not connect: ' . mysql_error());
  29. }
  30.  
  31. mysql_select_db("site", $con);
  32.        
  33. $firstname = strip_tags( $_POST[ 'firstname' ] );
  34. $surname = strip_tags( $_POST[ 'surname' ] );
  35.        
  36. $query = "SELECT * FROM Members WHERE firstname='" . $firstname . "' and surname=' " . $surname. "'";  
  37. $result = mysql_query( $query );
  38.        
  39. if ( mysql_num_rows($result) >= 1 ) {
  40.     // the page you want
  41. } else {
  42.     // redirect user to another page
  43.     header( "Location: signup.php" ); die;
  44. }
  45.  
  46. ?>
  47.        
  48. if (mysql_num_rows($result) == 1)
  49.    {
  50.    echo "great success"; //user continues loading page
  51.    }
  52. else
  53.    {
  54.    echo "fail"; //user is redirected to sign up page
  55.    }
  56.        
  57. $rows = mysql_num_rows($results);
  58.  
  59. if ($rows == 1)
  60. {
  61.    echo "login successful"; //user continues loading page
  62. }
  63. else
  64. {
  65.    header ('location: signup.php'); //user is redirected to sign up page
  66. }
  67.        
  68. if(mysql_num_rows($result) > 0){
  69.     echo "great success"; //user continues loading page
  70. }
  71. else
  72. {
  73.    echo "fail"; //user is redirected to sign up page
  74. }