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
<?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:
<?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>";
}
$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'>
<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>