Untitled
unknown
php
4 years ago
2.0 kB
23
Indexable
<?php
require "./dbconnect.php"; // Establishes connection to database
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST["username"])) {
$exists = false;
$user = $_POST["username"]; // username input in form
$pass = $_POST["password"]; // password input in form
$cpass = $_POST["cpassword"]; // confirm password input in form
$db_check = "SELECT * FROM `users`.`userdata` WHERE `username` = $user";
$result1 = $conn->query($db_check); // THIS IS NOT WORKING, IDK WHY !!!!!????
// debugging statements below -->
if(!$result1){
echo "check"; // Does not get printed
}
var_dump $result1; // Still, nothing printed here
// further below, nothing is executed.
if($result1->num_rows > 0){
$exists = true;
}
if (($pass == $cpass) && (!$exists)) {
$sql_insert = "INSERT INTO `users`.`userdata` (`username`, `password`) VALUES ('$user', '$pass')";
$result2 = $conn->query($sql_insert);
if (!$result2) {
$alert = "db_error";
require './alerts.php'; // if executed, will print error alert corresponding to db_error
} else {
$alert = "account_created";
require './alerts.php'; //if executed, will print success alert corresponding to account_created
}
} elseif ($pass != $cpass) {
$alert = "pass_not_match";
require './alerts.php'; // if executed, will print error alert corresponding to pass_not_match
} elseif ($exists) {
$alert = "user_exists";
require './alerts.php'; // if executed, will print error alert corresponding to user_exists
}
}
}
?>Editor is loading...