Guest User

problems... webnet

a guest
Jun 12th, 2013
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.75 KB | None | 0 0
  1. <?php
  2. //Start session for session variable gathering
  3. session_start();
  4. //get the database connection variables for DB connection
  5. $host= $_SESSION["dbhost"];
  6. $username= $_SESSION["dbuser"];
  7. $password= $_SESSION["dbpass"];
  8. $db_name= $_SESSION["dbname"];
  9. $tbl_name="promoters"; // Table name
  10. //Connect to the DB server
  11. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  12. //connect to the DB itself
  13. mysql_select_db("$db_name")or die("cannot select DB");
  14.  
  15. //password change variables
  16. $user = $_SESSION["username"];
  17. $newpassword = $_POST['newpassword'];
  18. $repeatnewpassword = $_POST['repeatnewpassword'];
  19.  
  20. //////////====NOTE THE ERROR COE NUMBERS WERE FOR MY TESTING PURPOSES SO I COULD SEE WHERE ERRORS WERE BEING THROWN====//////////
  21.  
  22. //validate the form and give the option to go back if they forgot something
  23. //newpassword empty
  24. if (empty($newpassword)){
  25.     echo "New Password was empty (ERROR 898)... Please try again.<br>";
  26.     echo "<a href='dashboard.php'>Click here to go back</a>";
  27.     exit();
  28.     }
  29. //repeatnewpassword empty
  30. if (empty($repeatnewpassword)){
  31.     echo "New Password was empty (ERROR 899)... Please try again.<br>";
  32.     echo "<a href='dashboard.php'>Click here to go back</a>";
  33.     exit();
  34.     }    
  35. // everything seems ok so lets move on
  36.  
  37. //find the database row for the currently logged in user
  38. $result = mysql_query("SELECT * FROM $tbl_name WHERE user='$user'");
  39.  
  40. //if that doesnt work throw the errors
  41. if(!$result)
  42. {
  43.    echo "an error occurred (ERROR 900)... Please try again.<br>";
  44.     echo "<a href='dashboard.php'>Click here to go back</a>";
  45.     exit();
  46. }
  47. ////////====note thie following section is whats throwing the error (ERROR 901)
  48. if ($row = mysql_fetch_assoc($result))
  49. {
  50.   echo "An error occurred (ERROR 901)... Please try again.<br>";
  51.     echo "<a href='dashboard.php'>Click here to go back</a>";
  52.     exit();
  53. }
  54.  
  55. //make sure new password and repeat newpassword are the same
  56. if($newpassword==$repeatnewpassword)
  57. {
  58. /// looks good lets do that swap out
  59.  
  60. ////===IM GOING TO HASH LATER BUT IM PUTTING THAT OFF UNTIL I GET THIS SCRIPT WORKING===////
  61. $hashpass = $newpassword;
  62.  
  63.     $sql=mysql_query("UPDATE $tbl_name SET pass='$hashpass' where user='$user'");
  64. }
  65. // if those dont line up throw the error
  66. else
  67. {
  68.     echo "Your new passwords dont line up!... Please try again.<br>";
  69.     echo "<a href='dashboard.php'>Click here to go back</a>";
  70.     exit();
  71. }
  72.  
  73. //if the swap out goes ok redirect to the dashboard
  74. if($sql)
  75. {
  76.     header("Location: ./dashboard.php");
  77.     exit();
  78. }
  79. //if not throw out the error
  80. else
  81. {
  82.    echo "An error occurred (ERROR 903)... Please try again.<br>";
  83.     echo "<a href='dashboard.php'>Click here to go back</a>";
  84.     exit();
  85. }  
  86.  
  87. //done
  88. ?>
Advertisement
Add Comment
Please, Sign In to add comment