Advertisement
Guest User

Untitled

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