This question already has an answer here:
- Can I mix MySQL APIs in PHP? 4 answers
This is my existing code:
<?php
include('config.php');
session_start();
if(isset($_POST['submit'])) {
if(!$_POST['username']) {
$error['username'] = "<p>Please supply your name.</p>
";
}
if(!$_POST['password']) {
$error['password'] = "<p>Please supply your password.</p>
";
}
if(!is_array($error)) {
$db = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
if($db === false) {
die('Could not connect: ' . mysqli_error());
}
$user = mysqli_real_escape_string($db, $_POST['username']);
$pass = mysqli_real_escape_string($db, password_hash($_POST['password'], PASSWORD_BCRYPT));
$query = "INSERT INTO users (USERNAME, PASSWORD) VALUES ('$user', '$pass')";
mysqli_query($query, $db);
mysqli_close($db);
}
}
?>
This just doesn't seem to work. The connection is fine because I am using the same process in another file and it works perfectly. I just wondered why the query isn't doing anything?
EDIT:
Here's the form and changed to mysqli in above:
<html>
<head>
<title>Add Users</title>
</head>
<body>
<form method="post" action="formProcess.php">
Username: <input type="text" name="username"><br> Password: <input type="password" name="password"><br>
<input type="submit">
</form>
</body>
</html>
</div>