<?php
$db = mysqli_connect('localhost', 'username', 'password', 'database');
$username = "";
$password = "";
$regcode = "";
if (isset($_POST['submit'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$regcode = $_POST['regcode'];
$sql_R = "SELECT * FROM regcode WHERE regcode='$regcode'";
$sql_R2 = "SELECT * FROM staff WHERE regcode='$regcode'";
$res_R2 = mysqli_query($db, $sql_R2);
$res_R = mysqli_query($db, $sql_R);
if ((mysqli_num_rows($res_R) > 0) && (mysqli_num_rows($res_R2) < 1)){
$query = "INSERT INTO staff (username, password, regcode)
VALUES ('.$username.', '.$password.', '".$regcode."')";
$results = mysqli_query($db, $query);
echo file_get_contents("register.html");
exit();
}else if(mysqli_num_rows($res_R2) > 0){
$regcode_error = "Reg.Code already used by someone, please inform administrator for further information.";
}else{
$regcode_error = "Reg.Code doesn't exists, please inform Administrator for further information.";
}
}
?>
Here's what happened: I'm trying to let my system recognize a code called 'regcode' from the database so when it's verified users will able to register their account, user won't be able to register their account IF the regcode is in use in the staff database or when the regcode isn't exist in the regcode database the problem is: - My database didn't add the new info after it's verified. - I've tried the other way such as testing the regcode invalid or being in use, and it works well by displaying the error message.
I'm trying to figure this out like hours, and I still can't get it. I'm new to php btw, thanks for the advice.