daily pastebin goal
37%
SHARE
TWEET

Untitled

a guest May 31st, 2017 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. session_start();
  3. //connect to database
  4. $db=mysqli_connect("localhost","root","","authentication");
  5. if(isset($_POST['register_btn']))
  6. {
  7.     $username=$_POST['username'];
  8.     $email=$_POST['email'];
  9.     $password=$_POST['password'];
  10.     $password2=$_POST['password2'];  
  11.      if($password==$password2)
  12.      {           //Create User
  13.             $password=md5($password); //hash password before storing for security purposes
  14.             $sql="INSERT INTO users(username,email,password) VALUES('$username','$email','$password')";
  15.             mysqli_query($db,$sql);  
  16.             $_SESSION['message']="You are now logged in";
  17.             $_SESSION['username']=$username;
  18.             header("location:home.php");  //redirect home page
  19.     }
  20.     else
  21.     {
  22.       $_SESSION['message']="The two password do not match";  
  23.      }
  24.    
  25.    
  26.     }
  27.  
  28.  
  29.  
  30.  
  31. ?>
  32. <!DOCTYPE html>
  33. <html>
  34. <head>
  35.   <title>REGISTRIRAJTE SE ZA KONTAKT!!!!</title>
  36.   <link rel="stylesheet" type="text/css" href="style.css"/>
  37. </head>
  38. <body>
  39. <div class="header">
  40.     <h1>Register, login and logout user php mysql</h1>
  41. </div>
  42.  
  43.  
  44. <?php
  45.     if(isset($_SESSION['message']))
  46.     {
  47.          echo "<div id='error_msg'>".$_SESSION['message']."</div>";
  48.          unset($_SESSION['message']);
  49.     }
  50. ?>
  51. <form method="post" action="register.php">
  52.   <table>
  53.      <tr>
  54.            <td>Username : </td>
  55.            <td><input type="text" name="username" class="textInput"></td>
  56.      </tr>
  57.      <tr>
  58.            <td>Email : </td>
  59.            <td><input type="email" name="email" class="textInput"></td>
  60.      </tr>
  61.       <tr>
  62.            <td>Password : </td>
  63.            <td><input type="password" name="password" class="textInput"></td>
  64.      </tr>
  65.       <tr>
  66.            <td>Password again: </td>
  67.            <td><input type="password" name="password2" class="textInput"></td>
  68.      </tr>
  69.       <tr>
  70.            <td></td>
  71.            <td><input type="submit" name="register_btn" class="Register" value="Registriraj"></td>
  72.      </tr>
  73.  
  74. </table>
  75. </form>
  76. </body>
  77. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top