I posted about this earlier in the week. Today I came back to review the post - and answer provided by Celauran. For the life of me, I can not find the original topic and posts. So... I am starting all over ... sorry for the double-post if my original topic is still out there somewhere.
At any rate, following is the problem. I'm a newbie to php (although I've 20 years of classical database development experience). I have figured out a few basics, creating input html files, database connect files and very basic posting files. But now I am trying to validate users. Initially my query was about checking for duplicate email addresses, but Celauran posted some script that also validated whether submitted emails were not only duplicated, but valid emails. Following is my coding thus far.
html post page - Title: register.html
Code: Select all
<body>
<form action="register_post.php" method="post">
First Name: <input type="text" name="FName" />
Last Name: <input type="text" name="LName" />
Email: <input type="text" name="EmailAddress" />
<input type="submit" />
</form>
</body>Code: Select all
<?php
// include database connection file, if connection doesn't work the include file will throw an error message
include '../####/db_files/db_connect.php';
// test code to find duplicate email addresses
// Query database to check if there are any matching Email addresses
$query = "SELECT * FROM ContactTbl WHERE EmailAddress='{$_POST['EmailAddress']}'";
$result = mysql_query($query);
// mysql_num_rows tests for the number of matchiing rows.
$num_rows = mysql_num_rows($result);
if ($num_rows>"0")
echo "Someone has already registered with this email address.";
else
// insert script inserts values from the register.html input fields into the appropriate table fields
$sql="INSERT INTO ContactTbl (FName, LName, EmailAddress)
VALUES
('$_POST[FName]','$_POST[LName]','$_POST[EmailAddress]')";
if (!mysql_query($sql,$link))
{
die('Error: ' . mysql_error());
}
echo "a record has been added to the database";
//following statement closes connection to databasee
mysql_close($link)
?>My only problem is the following message, if the user enters an email address that is already in the database.
Where is the error coming from?????Someone has already registered with this email address.Error: Query was empty