Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "xxx";
- $username = "xxx";
- $password = "xxx";
- $dbname = "xxx";
- function connectDB()
- {
- static $mysqli;
- if ($mysqli === NULL)
- {
- $mysqli = new mysqli($servername, $username, $password, $dbname);
- mysqli_set_charset($mysqli, 'utf8');
- }
- return $mysqli;
- }
- function checkUsername($mysqli)
- {
- connectDB(); //Apelezi conexiunea din functia de mai sus
- $query = mysqli_query($mysqli, "SELECT * FROM useri WHERE User = $username") or die(mysqli_error($mysqli));
- return $query;
- }
- function CreateNewUser()
- {
- connectDB(); //Apelezi conexiunea din functia de mai sus
- if (isset($_POST['username']) && isset($_POST['password']))
- {
- if (checkUsername($mysqli) == 0)
- {
- $stmt = $conn->prepare("
- INSERT INTO
- `useri`(
- `user`,
- `parola`,
- `tel`,
- `Permission`,
- `Acceptat`,
- `Activ`
- )
- VALUES (
- ?,
- ?,
- ?,
- ?,
- ?,
- ?)
- ");
- $stmt->bind_param("ssssss", $username, $password, $tel, $permission, $acceptat, $activ);
- $username = mysqli_real_escape_string($conn, $_POST['username ']);
- $password= mysqli_real_escape_string($conn, $_POST['password']);
- $tel = mysqli_real_escape_string($conn, $_POST['tel']);
- $permission = "0"; // string
- $acceptat= "0"; // string
- $activ= "0"; // string
- $smsg = "Contul a fost înregistrat cu succes!";
- } else
- {
- $fmsg ="Acest nume de utilizator este deja folosit!";
- }
- if (!$stmt->execute())
- {
- echo "Execuția a întâmpinat o eroare: (" . $stmt->errno . ") " . $stmt->error;
- }
- $stmt->close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement