Is the code safe from mysql injections?
Possibly some mistakes in code?
The code is working... i only want to know possibly some mistakes, etc....
connect to database
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
somewhere read that set character is necessary for security
$mysqli->set_charset('utf8');
get users's post email
$email= $mysqli->real_escape_string($_POST['email']);
get corresponding values from columns email, username and confirmationCode (if users enters already registered email, get corresponding values (within the row))
if ($stmt = mysqli_prepare($mysqli, "SELECT email, username, confirmationCode FROM $create_new_table WHERE email = ? ")) {
as i understand this passes users's entered email to value that must be used to check values in mysql?
$stmt->bind_param('s', $email);
execute query
$stmt->execute();
? stores what result? if users's entered email matches email in mysql?
$stmt->store_result();
can not fully understand... bind results... what is the difference from bind_param?
$stmt->bind_result($email, $username, $confirmationCode);
get results from mysql?
$stmt->fetch();
here inform visitor if email is already registered
elseif( (strlen($_POST['email']) > 0) and ($stmt->num_rows > 0) ) {
$error .= '<font color="#FF0000">The email is already registered. Please, choose other email or <a href="reset-password.php">reset password</a>.
</font>';