SHARE
TWEET

Registrer.php

a guest Dec 29th, 2016 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.    include('include/session.php');
  3.    if ($userlevel_session < 10) {
  4.      header('Location: adgangforbudt.php');
  5.    }
  6.  
  7.    function renderForm($username1 = '', $navn1 ='', $email1 = '', $password1 ='', $steam1 ='', $error = '', $id = '') {
  8. ?>
  9. <!DOCTYPE html>
  10. <html lang="en">
  11.  
  12. <head>
  13.  
  14.     <meta charset="utf-8">
  15.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  16.     <meta name="viewport" content="width=device-width, initial-scale=1">
  17.     <meta name="description" content="">
  18.     <meta name="author" content="">
  19.  
  20.     <title><?php if ($id != '') { echo "Edit Record"; } else { echo "New Record"; } ?></title>
  21.  
  22.     <!-- Bootstrap Core CSS -->
  23.     <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  24.  
  25.     <!-- MetisMenu CSS -->
  26.     <link href="vendor/metisMenu/metisMenu.min.css" rel="stylesheet">
  27.  
  28.     <!-- Custom CSS -->
  29.     <link href="dist/css/sb-admin-2.css" rel="stylesheet">
  30.  
  31.     <!-- Custom Fonts -->
  32.     <link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
  33.  
  34.     <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  35.     <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  36.     <!--[if lt IE 9]>
  37.         <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
  38.         <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
  39.     <![endif]-->
  40.  
  41. </head>
  42.  
  43. <body>
  44.  
  45.     <div id="wrapper">
  46.  
  47.     <?php include 'include/sidebar.php';?>
  48.  
  49.         <!-- Page Content -->
  50.         <div id="page-wrapper">
  51.             <div class="container-fluid">
  52.                 <div class="row">
  53.                     <div class="col-lg-12">
  54.                         <h1 class="page-header"><?php if ($id != '') { echo "Edit Record"; } else { echo "New Record"; } ?></h1>
  55.                     </div>
  56.                     <div class="col-lg-6">
  57.                       <form role="form" method="post" action="">
  58.                         <?php
  59.                         if ($error != '') { echo "$error"; }
  60.                         ?>
  61.                         <div class="form-group">
  62.                           <label>Brugernavn:</label>
  63.                           <input class="form-control" name="username" value="<?php echo $username1; ?>">
  64.                         </div>
  65.                         <div class="form-group">
  66.                           <label>Navn:</label>
  67.                           <input class="form-control" name="navn" value="<?php echo $navn1; ?>">
  68.                         </div>
  69.                         <div class="form-group">
  70.                           <label>Email:</label>
  71.                           <input class="form-control" name="email" value="<?php echo $email1; ?>">
  72.                         </div>
  73.                         <div class="form-group">
  74.                           <label>Password:</label>
  75.                           <input class="form-control" name="password" placeholder="Password" type="password">
  76.                         </div>
  77.                         <div class="form-group">
  78.                           <label>Steam link:</label>
  79.                           <input class="form-control" name="steam" value="<?php echo $steam1; ?>">
  80.                         </div>
  81.                         <div class="form-group">
  82.                           <label>Administrator?</label>
  83.                             <label class="checkbox-inline">
  84.                               <input type="checkbox" value="10" name="admin"> 
  85.                             </label>
  86.                         </div>
  87.                         <input type="submit" name="submit" value="Tilføj/Update" class="btn btn-danger">
  88.                       </form>
  89.                     </div>
  90.                     <!-- /.col-lg-12 -->
  91.                 </div>
  92.                 <!-- /.row -->
  93.             </div>
  94.             <!-- /.container-fluid -->
  95.         </div>
  96.         <!-- /#page-wrapper -->
  97.     </div>
  98.     <!-- /#wrapper -->
  99.  
  100.     <?php }
  101.  
  102.     include_once('include/mysql_config.php');
  103.  
  104.     if (isset($_GET['id'])) {
  105.  
  106.       if (isset($_POST['submit'])) {
  107.  
  108.         if (is_numeric($_POST['id'])) {
  109.           $id = $_POST['id'];
  110.           $username = htmlentities($_POST['username']);
  111.           $navn = htmlentities($_POST['navn']);
  112.           $email = htmlentities($_POST['email']);
  113.           $password = md5 ($_POST['password']);
  114.           $admin = htmlentities($_POST['admin']);
  115.           $steamlink = htmlentities($_POST['steam']);
  116.  
  117.           if ($username == '' || $email == '' || $password == '') {
  118.  
  119.             $error = "<div class='alert alert-danger alert-dismissable'>
  120.                      <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
  121.                      FEJL! Alle felter skal udfyldes!.
  122.                      </div>";
  123.             renderForm($username, $navn, $email, $password, $steamlink, $admin, $id);
  124.  
  125.           }
  126.           $mysql_get_users = mysqli_query($dbconnect, "SELECT * FROM users where username='$username'");
  127.           $get_rows = mysqli_affected_rows($dbconnect);
  128.  
  129.           if($get_rows >=1){
  130.             $error = "<div class='alert alert-danger alert-dismissable'>
  131.                      <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
  132.                      FEJL! Brugernavnet eksistere allerede!.
  133.                      </div>";
  134.            renderForm($username, $navn, $email, $password, $steamlink, $admin, $id);
  135.           } else {
  136.             if ($stmt = $dbconnect->prepare("UPDATE users SET username = ?, navn = ?, email = ?, password = ?, userlevel = ?, steam = ? WHERE id=?")) {
  137.               $stmt->bind_param("ssssisi", $username, $navn, $email, $password, $admin, $steamlink, $id);
  138.               $stmt->execute();
  139.               $stmt->close();
  140.             } else {
  141.               echo "ERROR: SQL statement";
  142.             }
  143.             header("Location: users.php");
  144.           }
  145.         } else {
  146.           echo "ERROR";
  147.         }
  148.       } else {
  149.         if (is_numeric($_GET['id']) && $_GET['id'] > 0) {
  150.           $id = $_GET['id'];
  151.  
  152.           if ($stmt = $dbconnect->prepare("SELECT * FROM users WHERE id=?")) {
  153.             $stmt->bind_param("i", $id);
  154.             $stmt->execute();
  155.  
  156.             $result = $stmt->get_result();
  157.             $num_of_rows = $result->num_rows;
  158.             $row = $result->fetch_assoc();
  159.             $id = $row['user_id'];
  160.             $username = $row['username'];
  161.             $email = $row['email'];
  162.             $password = $row['password'];
  163.             $navn = $row['navn'];
  164.             $steamlink = $row['steam'];
  165.             $admin = $row['userlevel'];
  166.  
  167.             renderForm($username, $navn, $email, NULL, $steamlink, NULL, $id);
  168.             $stmt->free_result();
  169.             $stmt->close();
  170.           } else {
  171.             echo "Du er grim!";
  172.           }
  173.         }else {
  174.           header("Location: users.php");
  175.         }
  176.       }
  177.     } else {
  178.       if (isset($_POST['submit'])) {
  179.         $username = htmlentities($_POST['username']);
  180.         $navn = htmlentities($_POST['navn']);
  181.         $email = htmlentities($_POST['email']);
  182.         $password = md5 ($_POST['password']);
  183.         $admin = htmlentities($_POST['admin']);
  184.         $steamlink = htmlentities($_POST['steam']);
  185.  
  186.         if ($username == '' || $email == '' || $password == '') {
  187.  
  188.           $error = "<div class='alert alert-danger alert-dismissable'>
  189.                    <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
  190.                    FEJL! Alle felter skal udfyldes!.
  191.                    </div>";
  192.           renderForm($username, $navn, $email, $password, $steamlink, $admin, $id);
  193.  
  194.         }
  195.         $mysql_get_users = mysqli_query($dbconnect, "SELECT * FROM users where username='$username'");
  196.         $get_rows = mysqli_affected_rows($dbconnect);
  197.  
  198.         if($get_rows >=1){
  199.           $error = "<div class='alert alert-danger alert-dismissable'>
  200.                    <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
  201.                    FEJL! Brugernavnet eksistere allerede!.
  202.                    </div>";
  203.           renderForm($username, $navn, $email, $password, $steamlink, $admin, $id);
  204.         } else {
  205.           if ($stmt = $dbconnect->prepare("INSERT INTO users (username, navn, email, password, userlevel, steam) VALUES (?,?,?,?,?,?) ")) {
  206.             $stmt->bind_param("ssssis", $username, $navn, $email, $password, $admin, $steamlink);
  207.             $stmt->execute();
  208.             $stmt->close();
  209.           } else {
  210.             echo "ERROR: SQL statement";
  211.           }
  212.           header("Location: users.php");
  213.         }
  214.       } else {
  215.         renderForm();
  216.       }
  217.     }
  218. $dbconnect->close();
  219. ?>
  220.  
  221.     <!-- jQuery -->
  222.     <script src="vendor/jquery/jquery.min.js"></script>
  223.  
  224.     <!-- Bootstrap Core JavaScript -->
  225.     <script src="vendor/bootstrap/js/bootstrap.min.js"></script>
  226.  
  227.     <!-- Metis Menu Plugin JavaScript -->
  228.     <script src="vendor/metisMenu/metisMenu.min.js"></script>
  229.  
  230.     <!-- Custom Theme JavaScript -->
  231.     <script src="dist/js/sb-admin-2.js"></script>
  232.  
  233. </body>
  234.  
  235. </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