Advertisement
Guest User

Untitled

a guest
Nov 13th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.56 KB | None | 0 0
  1. <?php
  2. /*
  3.  * This page changes the user's password.
  4.  */
  5.  
  6. session_start();
  7.  
  8. $pwdvalid = true;
  9.  
  10. $uname = $_SESSION['name'];
  11.  
  12. $newpass = $_POST['newpass'];
  13.  
  14. // DB connection info
  15. $servername = "tund.cefns.nau.edu";
  16. $username = "mlb652script";
  17. $password = "ChelseaFC123";
  18. $dbname = "mlb652";
  19.  
  20. // Making connection
  21. $conn = new mysqli($servername, $username, $password, $dbname);
  22.  
  23. // Checking connection
  24. if ($conn->connect_error) {
  25.     die("Connection failed: " . $conn->connect_error);
  26. }
  27.  
  28. // Sql query to change password
  29. $sql = "UPDATE users SET pwd = '$newpass' where username = '$uname'";
  30.  
  31. if (empty($newpass)) {
  32.     $pwdvalid = false;
  33. }
  34.  
  35. if ($pwdvalid == true) {
  36.    
  37.     // Run query
  38.     if ($conn->query($sql) === TRUE) {
  39.         echo "Record updated successfully";
  40.     } else {
  41.         echo "Error updating record: " . $conn->error;
  42.     }
  43.  
  44.     // Redirect back to userpage
  45.     header("Location: http://cefns.nau.edu/~mlb652/userpage.php");
  46.  
  47.  
  48. }
  49.  
  50. ?>
  51.  
  52. <HTML>
  53.     <head>
  54.         <link href='https://fonts.googleapis.com/css?family=Muli' rel='stylesheet' type='text/css'>
  55.         <link rel="stylesheet" type="text/css" href="main_style.css">
  56.         <link rel="stylesheet" type="text/css" href="article_style.css">
  57.         <title>Gameplay</title>
  58.     </head>
  59.  
  60.     <!-- Begin top bar used to display page title -->
  61.  
  62.     <div id="pagecontainer">
  63.  
  64.         <div class="topbar">
  65.  
  66.         <h1>
  67.             <a href="index.php">
  68.             <img src="./images/altmid.png" alt="Alt-Mid Banner" title="Alt-Mid"/>
  69.             </a>
  70.         </h1>
  71.  
  72.     </div>
  73.  
  74.     <!-- end top bar -->
  75.  
  76.     <!-- Begin Sidebar -->
  77.  
  78.     <div class="Sidebar">
  79.  
  80.         <h1>User Page</h1>
  81.         <p>Welcome to your user page, here you can edit your details or delete your account.</p>
  82.  
  83.         <div id="logo">
  84.             <a href="mysql_connect_test.php">
  85.             <img src="./images/log.png">
  86.             </a>   
  87.         </div>
  88.  
  89.  
  90.     </div>
  91.  
  92.     <!-- End Sidebar -->
  93.  
  94.     <!-- Begin top menu table -->
  95.  
  96.     <div>
  97.  
  98.         <section class="topmenu">
  99.  
  100.             <div class="top_opt">
  101.                 <img src="./images/pronews.png" alt="Pro News" title="Pro News"/>
  102.             </div>
  103.  
  104.             <div class="top_opt">
  105.                 <a href="gameplay.php">
  106.                 <img src="./images/gameplay.png" alt="Gameplay" title="Gameplay"/>
  107.                 </a>
  108.             </div>
  109.  
  110.             <div class="top_opt">
  111.                 <a href="community.php">
  112.                 <img src="./images/community.png" alt="Community" title="Community"/>
  113.                 </a>
  114.             </div>
  115.  
  116.         </section>
  117.  
  118.     </div>
  119.  
  120.     <!-- End top menu table -->
  121.  
  122.     <!-- Begin Article -->
  123.  
  124.     <section class ="columns">
  125.  
  126.         <div class ="article">
  127.  
  128.             <!-- Forms to allow the user to change password or email -->
  129.  
  130.             <h1>Password invalid, try again.</h1><br><br>
  131.  
  132.             <form action="pwdchange.php" method="POST">
  133.  
  134.                 <input type="text" name="newpass" id-"newpass" size='50' maxlength='75'>
  135.  
  136.                 <input type="submit" value="Change">
  137.  
  138.             </form>
  139.                
  140.         </div>
  141.     </section> 
  142.  
  143.         <div class="footer">
  144.  
  145.         <div class="contact">
  146.             Email: mlb652@nau.edu<br>
  147.             Phone: +44123456789<br>
  148.             Mail: 10 Downing Street, London, SW1A 2AA
  149.         </div>
  150.  
  151.         <div class="logout">
  152.  
  153.             <?php
  154.             // If the user currently has a session then display a logout button so the user can end it.
  155.             if (isset($_SESSION['name'])) {
  156.                 echo "<form action='logout.php' method='POST'>
  157.  
  158.                         <input type='submit' value='Logout'>
  159.  
  160.                        </form>";
  161.             }
  162.  
  163.             ?>
  164.  
  165.         </div>
  166.  
  167.         <div class="notifications">
  168.             <?php
  169.             // Displays the user name in the notifications window if a session exists.
  170.             if (isset($_SESSION['name'])) {
  171.                 echo "Welcome  ";
  172.                 echo $_SESSION['name'];
  173.                 echo "!";
  174.             }
  175.                 else{
  176.                     echo "0 New Notifications!";
  177.                 }
  178.             ?>
  179.         </div>
  180.  
  181.     </div>
  182.  
  183.         </div>
  184.  
  185. </div>
  186.  
  187. </HTML>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement