Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Start session for session variable gathering
- session_start();
- //get the database connection variables for DB connection
- $host= $_SESSION["dbhost"];
- $username= $_SESSION["dbuser"];
- $password= $_SESSION["dbpass"];
- $db_name= $_SESSION["dbname"];
- $tbl_name="promoters"; // Table name
- //Connect to the DB server
- mysql_connect("$host", "$username", "$password")or die("cannot connect");
- //connect to the DB itself
- mysql_select_db("$db_name")or die("cannot select DB");
- //password change variables
- $user = $_SESSION["username"];
- $newpassword = $_POST['newpassword'];
- $repeatnewpassword = $_POST['repeatnewpassword'];
- //////////====NOTE THE ERROR COE NUMBERS WERE FOR MY TESTING PURPOSES SO I COULD SEE WHERE ERRORS WERE BEING THROWN====//////////
- //validate the form and give the option to go back if they forgot something
- //newpassword empty
- if (empty($newpassword)){
- echo "New Password was empty (ERROR 898)... Please try again.<br>";
- echo "<a href='dashboard.php'>Click here to go back</a>";
- exit();
- }
- //repeatnewpassword empty
- if (empty($repeatnewpassword)){
- echo "New Password was empty (ERROR 899)... Please try again.<br>";
- echo "<a href='dashboard.php'>Click here to go back</a>";
- exit();
- }
- // everything seems ok so lets move on
- //find the database row for the currently logged in user
- $result = mysql_query("SELECT * FROM $tbl_name WHERE user='$user'");
- //if that doesnt work throw the errors
- if(!$result)
- {
- echo "an error occurred (ERROR 900)... Please try again.<br>";
- echo "<a href='dashboard.php'>Click here to go back</a>";
- exit();
- }
- ////////====note thie following section is whats throwing the error (ERROR 901)
- if ($row = mysql_fetch_assoc($result))
- {
- echo "An error occurred (ERROR 901)... Please try again.<br>";
- echo "<a href='dashboard.php'>Click here to go back</a>";
- exit();
- }
- //make sure new password and repeat newpassword are the same
- if($newpassword==$repeatnewpassword)
- {
- /// looks good lets do that swap out
- ////===IM GOING TO HASH LATER BUT IM PUTTING THAT OFF UNTIL I GET THIS SCRIPT WORKING===////
- $hashpass = $newpassword;
- $sql=mysql_query("UPDATE $tbl_name SET pass='$hashpass' where user='$user'");
- }
- // if those dont line up throw the error
- else
- {
- echo "Your new passwords dont line up!... Please try again.<br>";
- echo "<a href='dashboard.php'>Click here to go back</a>";
- exit();
- }
- //if the swap out goes ok redirect to the dashboard
- if($sql)
- {
- header("Location: ./dashboard.php");
- exit();
- }
- //if not throw out the error
- else
- {
- echo "An error occurred (ERROR 903)... Please try again.<br>";
- echo "<a href='dashboard.php'>Click here to go back</a>";
- exit();
- }
- //done
- ?>
Advertisement
Add Comment
Please, Sign In to add comment