Advertisement
Guest User

New

a guest
Apr 11th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.70 KB | None | 0 0
  1. <?php
  2. $servername = "xxx";
  3. $username = "xxx";
  4. $password = "xxx";
  5. $dbname = "xxx";
  6. function connectDB()
  7.     {
  8.         static $mysqli;
  9.             if ($mysqli === NULL)
  10.             {
  11.                 $mysqli = new mysqli($servername, $username, $password, $dbname);
  12.                 mysqli_set_charset($mysqli, 'utf8');
  13.             }
  14.         return $mysqli;
  15.     }
  16.  
  17. function checkUsername($mysqli)
  18.     {
  19.         connectDB(); //Apelezi conexiunea din functia de mai sus
  20.         $query = mysqli_query($mysqli, "SELECT * FROM useri WHERE User = $username") or die(mysqli_error($mysqli));
  21.         return $query;
  22.     }
  23.  
  24. function CreateNewUser()
  25.     {
  26.         connectDB(); //Apelezi conexiunea din functia de mai sus
  27.         if (isset($_POST['username']) && isset($_POST['password']))
  28.         {
  29.           if (checkUsername($mysqli) == 0)
  30.           {
  31.                 $stmt = $conn->prepare("
  32.                 INSERT INTO
  33.                 `useri`(
  34.                 `user`,
  35.                 `parola`,
  36.                 `tel`,
  37.                 `Permission`,
  38.                 `Acceptat`,
  39.                 `Activ`
  40.                 )
  41.                 VALUES (
  42.                 ?,
  43.                 ?,
  44.                 ?,
  45.                 ?,
  46.                 ?,
  47.                 ?)
  48.                 ");
  49.  
  50.                 $stmt->bind_param("ssssss", $username, $password, $tel, $permission, $acceptat, $activ);
  51.  
  52.                 $username = mysqli_real_escape_string($conn, $_POST['username ']);
  53.                 $password= mysqli_real_escape_string($conn, $_POST['password']);
  54.                 $tel = mysqli_real_escape_string($conn, $_POST['tel']);
  55.                 $permission = "0"; // string
  56.                 $acceptat= "0"; // string
  57.                 $activ= "0"; // string
  58.  
  59.                 $smsg = "Contul a fost înregistrat cu succes!";
  60.             } else
  61.             {
  62.                 $fmsg ="Acest nume de utilizator este deja folosit!";
  63.             }
  64.  
  65.             if (!$stmt->execute())
  66.             {
  67.                 echo "Execuția a întâmpinat o eroare: (" . $stmt->errno . ") " . $stmt->error;
  68.             }
  69.                 $stmt->close();
  70.           }
  71.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement