PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE records ( name TEXT, password TEXT ); INSERT INTO records (name, password) VALUES ('Coloured', "colourediscool"); INSERT INTO records (name, password) VALUES ('Ruli', "ruliisprobablycooler"); UPDATE records SET Password = MD5(Password); SELECT * FROM records;
Copy Clear
Copy Format Clear
<?php // signup.php require 'db.php'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $username = $_POST['username']; $password = $_POST['password']; // Validate input if (empty($username) || empty($password)) { echo "Please enter both username and password."; exit; } // Check if the username already exists $stmt = $pdo->prepare("SELECT * FROM users WHERE username = ?"); $stmt->execute([$username]); $user = $stmt->fetch(); if ($user) { echo "Username is already taken!"; } else { // Hash the password before storing it $hashedPassword = password_hash($password, PASSWORD_BCRYPT); // Insert user into the database $stmt = $pdo->prepare("INSERT INTO users (username, password) VALUES (?, ?)"); $stmt->execute([$username, $hashedPassword]); echo "Registration successful! You can now <a href='login.php'>login</a>."; } } ?>
Show:  
Copy Clear