I'm creating a user registration form for my website in PHP and 'POST' the user data to my SQL database. When I made my first two users it posted the user info to my database such as username and email ALONG with a row of NULL for each field. I didn't change anything in my PHP code but now when I go to create a user it adds a new row to the database but all the fields are NULL, and a hash code for password. I don't know why its coming up as NULL. Below I will include my register.php code.
<?php
#session_start();
#if(isset($_SESSION['User']))
#{
# header("Location: home.php");
#}
include_once 'dbconnect.php';
#if(isset($_POST['submit']))
#
$uname = $_POST['uname'];
$email = $_POST['email'];
$upass = $_POST['upass'];
$stmt = $dbh->prepare("SELECT COUNT(*) as `emailcount` FROM `User` WHERE email=:email");
$stmt->execute(array("email" => $_POST['email']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($row['emailcount'] > 0) {
echo "<script>alert('Email $email already exists in our system. Please try another email')</script>";
} else {
$stmt = $dbh->prepare("INSERT INTO User(`uname`, `email`, `upass`) VALUES (:uname, :email, :upass)");
$stmt->execute(array("uname" => $_POST['uname'], "email" => $_POST['email'], "upass" => md5($_POST['upass'])));
}
?>
I will also include my HTML form that we are working with here
<form method='post' action='register.php'>
<pre>
<div>
<label>Name : (letters only)*</label>
<input type="text" name="uname" pattern="[A-Za-z]+" title="only letters" required />
</div>
<div>
<label>E-mail : (xyz@zyx.com)*</label>
<input type="email" name="email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$" title="xyz@something.com" required />
</div>
<div>
<label>password : (at least 6 chars)</label>
<input type="password" name="upass" pattern=".{6,}" title="Six or more characters" required />
</div>
<input type='submit' name='submit' value='Sign Up'>
</pre>
</form>