Unable to post to my Mysql database using my HTML registration form: UPDATED CODE


so im trying to create a registration form for my website and am using a SQL database using phpmyadmin. I have done a ton of research on how to create the PHP file that will add the User to my database after creating their account. To the best of my knowledge, i have the correct execution and code but when i go to my website, create a user and go to my phpmyadmin to check my database table to see if the user is created..it is not.Below i will include my code for connection php file along with my register.php file. At this point i have no idea as to what is wrong with my code that is not actually POSTing and data to the database after creating an account on my website.

Below is my UPDATED dbconnect.php file which is included in my register.php


/*** mysql hostname ***/
$hostname = 'localhost';
/*** mysql username ***/
$username = '******';
/*** mysql password ***/
$password = '******';

try {
function testdb_connect (){
    $dbh = new PDO("mysql:host=$hostname;dbname=*******", $username, $password);
return ($dbh);
$dbh = testdb_connect();
catch(PDOException $e) {
    echo $e->getMessage();


Here is the UPDATED PHP section of register.php:

 header("Location: home.php");
include_once 'dbconnect.php';

$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>";

    $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'])));


And here is the UPDATED HTML form which creates the user account and is supposed to POST to my database table:

    <form method='post' action='register.php'>
            <label>Name : (letters only)*</label>
<input type="text" name="uname" pattern="[A-Za-z]+" title="only letters" required />

<label>E-mail : ([email protected])*</label>
<input type="email" name="email" pattern="[a-z0-9._%+-][email protected][a-z0-9.-]+\.[a-z]{2,4}$" title="[email protected]" required />

<label>password : (at least 6 chars)</label>
<input type="password" name="upass" pattern=".{6,}" title="Six or more characters" required />

<input type='submit' name='submit' value='Sign Up'>

You need to uncomment this:

$uname = mysql_real_escape_string($_POST['uname']);
$email = mysql_real_escape_string($_POST['email']);
$upass = md5(mysql_real_escape_string($_POST['pass']));