Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Change this to your connection info.
- include('mysqli_connect.php');
- // Now we check if the data was submitted, isset will check if the data exists.
- if (!isset($_POST['username'], $_POST['password'], $_POST['email'])) {
- // Could not get the data that should have been sent.
- die ('<script>alert("ERROR ID: R#1");location.href="../index.php";</script>');
- }
- // Make sure the submitted registration values are not empty.
- if (empty($_POST['username']) || empty($_POST['password']) || empty($_POST['email'])) {
- // One or more values are empty...
- die ('<script>alert("ERROR ID: R#2");location.href="../index.php";</script>');
- }
- // We need to check if the account with that username exists
- if ($stmt = $mysqli_web->prepare('SELECT id, password FROM user WHERE username = ?')) {
- // Bind parameters (s = string, i = int, b = blob, etc), hash the password using the PHP password_hash function.
- $stmt->bind_param('s', $_POST['username']);
- $stmt->execute();
- $stmt->store_result();
- // Store the result so we can check if the account exists in the database.
- if ($stmt->num_rows > 0) {
- // Username already exists
- echo 'Username exists, please choose another!<br><a href="index.php">Back</a>';
- } else {
- // Username doesnt exists, insert new account
- if ($stmt = $mysqli_web->prepare('INSERT INTO user (username, password, email) VALUES (?, ?, ?)')) {
- // We do not want to expose passwords in our database, so hash the password and use password_verify when a user logs in.
- //date_default_timezone_set('Europe/Stockholm');
- //$date = date("Y/m/d");
- $password = password_hash($_POST['pass'], PASSWORD_DEFAULT);
- $stmt->bind_param('ssss', $_POST['username'], $password, $_POST['email']);
- $stmt->execute();
- echo 'You have successfully registered, you can now login!<br><a href="index.php">Login</a>';
- } else {
- echo 'Could not prepare statement!1';
- //echo error_reporting(E_ALL);
- }
- }
- $stmt->close();
- } else {
- echo 'Could not prepare statement!2';
- }
- $mysqli_web->close();
- ?>
- <?php
- // Enter your Host, username, password, database below.
- // I left password empty because i do not set password on localhost.
- $mysqli_web = mysqli_connect("localhost","root","mypass","web_wan");
- $mysqli_hub = mysqli_connect("localhost","root","mypass","hub");
- $mysqli_0001 = mysqli_connect("localhost","root","mypass","mugame_0001");
- // Check connection
- if (mysqli_connect_errno())
- {
- echo "Failed to connect to MySQL: " . mysqli_connect_error();
- }
- ?>
- <form class="nk-sign-form-register" action="php/mysqli_action.php" method="post">
- <input class="form-control" type="text" name="username" placeholder="Username" required>
- <div class="nk-gap-2"></div>
- <input class="form-control" type="email" name="email" placeholder="Email" required>
- <div class="nk-gap-2"></div>
- <input class="form-control" type="text" name="password" placeholder="Password" required>
- <div class="nk-gap-2"></div>
- <div class="float-left">A password will be emailed to you.</div>
- <button class="nk-btn nk-btn-color-white link-effect-4 float-right" name="doreg">Register</button>
- </form>
Add Comment
Please, Sign In to add comment