I'm not sure how to title this; been wrestling with this for hours it's kind of a weird problem.
I have the following prepared statement:
$query = mysqli_prepare($con, "INSERT INTO users
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$query->bind_param('issssssisisiiisssssssssissssi',
$empty, $fname, $lname, $username,
$em, $hash, $date, $empty,
$empty, $empty, $profile_pic, $zero,
$zero, $zero, $no, $comma,
$empty, $empty, $empty, $empty,
$empty, $show, $empty, $empty,
$empty, $banner_pic, $banner_pic_two, $token, $two);
$query->execute();
$query->close();
if ($query) {
array_push($error_array, "<span>Check Your Email to Activate Your Account!</span><br>");
There is allot of checks and balances before I get to this point but I'll try and focus this if I can. When I fill out the register form, I get the message Check Your Email to Activate Your Account!
So I do this and activate and that checks out too. When I go to login, it's not in the dB - so of course I get an error msg. I can also see in phpmyAdmin that it's not there. So I was thinking it's somewhere in here $query->bind_param
. Went through this and how it corresponds to dB and it look good.
BUT (& this is weird), when I enter a First Name and Last Name of someone who is already in the dB, the registration works. I can't use the same email, (I'll get an error message) but I also can't use a new name with the new email. The names have to be of someone ALREADY in the dB. This is how $fname
and $lname
are input.
<div class="account-row">
<label for="firstname">FIRST NAME</label>
<input type="text" class="account-input" name="reg_fname" id="firstname" value="<?php if(isset($_SESSION['reg_fname'])){
echo $_SESSION['reg_fname'];
}
?>">
</div>
<div class="account-row">
<label for="lastname">LAST NAME</label>
<input type="text" class="account-input" name="reg_lname" id="lastname" value="<?php if(isset($_SESSION['reg_lname'])){
echo $_SESSION['reg_lname'];
}
?>">
</div>
This is how they are handled once the form is submitted:
//Declaring varibales to prevent errors
$fname = ""; //First Name
$lname = ""; //Last Name
$email = ""; //email
$em2 = ""; //email 2
$password = ""; //password
$password2 = ""; //password 2
$date = ""; //Sign up date
$banner_pic = "assets/images/banner_pics/default/default.gif";
$banner_pic_two = "assets/images/banner_pics/default/default2.gif";
$error_array = array(); //Holds error messages
if(isset($_POST['register_button'])){
//Registration form values
// First name
$fname = strip_tags($_POST['reg_fname']); //Remove html tags
$fname = str_replace(' ', '', $fname); //Removes spaces
$fname = ucfirst(strtolower($fname)); //Uppercase first letter
$_SESSION['reg_fname'] = $fname; //Stores first name into session variable
// Last name
$lname = strip_tags($_POST['reg_lname']); //Remove html tags
$lname = str_replace(' ', '', $lname); //Removes spaces
$lname = ucfirst(strtolower($lname)); //Uppercase first letter
$_SESSION['reg_lname'] = $lname; //Stores last name into session variable
Beyond this I have some code that concats
the first and last name to create a username and adds integers to the end if it already exists. This is working, b/c since the names are already in the dB, it just keeps adding 1,2,3 etc. on the end however many times I sign up with it. But when I go back to trying to use a new First Name and Last Name, (once again) it won't enter the dB. Is anyone able to see from what I posted where the issue might be? I'm working locally, so am wondering if it has something to do with session variables...but I can't see how?