Hi please help me. My cousin is studying but doesn't understand where he is going wrong. He has to
"Create an XHTML form allowing dealers to create an account with the site.
The form must require only basic contact details; chosen username, chosen password and email address. Account details are to be stored in your MySQL database.
The system must prevent duplicate usernames being chosen. Do not use the email address as a username. Newly created accounts should remain inactive until they are verified by handshaking the email details"
He code he has done so far is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Registration</title>
<link rel="stylesheet" type="text/css" href="sitestyle.css" /> <!-- test.css - external style sheet -->
<style type="text/css">
</style>
</head>
<body>
<h1>Second Hand Records</h1>
<hr />
<h2> Register form </h2>
<p> Please enter your details here:</p>
<form action="register.php" method="post">
<p>Surname:<br /> <input type="text" size="20" name="txtSurName" /></p>
<p>First Name:<br /> <input type="text" size="20" maxlength="40" name="txtFirstName" /></p>
<p>User Name:<br /> <input type="text" size="20" name="txtUserName" /></p>
<p>Password:<br /> <input type="password" size="20" maxlength="8" name="txtPassword" /></p>
<p>Email:<br /> <input type="text" size="20" name="txtEmail" /></p>
<p><input type="submit" name="cmdSubmit" value="Submit" /> </p>
</form>
</body>
</html>
register.php
<?php echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; ?>
=\"1.0\" encoding=\"UTF-8\"?>\n"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/tr/xhtml1/DTD/xhtml11.dtd" >
<?php
$host = "*****";
$username = "***"; //connection to db
$password = "*****";
$db_name = "mdb_st622";
$tbl_name="Dealers";
//adapted from: http://www.techsupportforum.com/design-forum/web-design-programming/287560-solved-connecting-webpage-mysql-database.html
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$LName=$_POST['txtSurName'];
$FName=$_POST['txtFirstName'];
$UserName=$_POST['txtUserName'];
$Password=$_POST['txtPassword'];
$Email=$_POST['txtEmail'];
$query = "SELECT * FROM $tbl_name WHERE 'UserName' = '$UserName'"; //Attempting to see if username already exists. Code does not work
$result = mysql_query($query);
if(mysql_affected_rows() > 0)
{
print 'name already in use';
}
else
{
$sql="INSERT INTO $tbl_name(LName, FName, UserName, Password, Email)VALUES('$LName', '$FName', '$UserName', password('$Password'), '$Email')";
$result=mysql_query($sql);
}
$characters = "/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/";
if (preg_match($characters, $Email)) {
echo "Email address is valid.";
} else {
echo "Email address is <u>not</u> valid.";
}
?>
<?php
$create = "Account created";
//echo $create;
echo '<a href="verifyaccount.html">Please click here to verify</a>';
?>
Any help is much appreciate as I don't understand this at all.
Merry Christmas & Happy New Year
thanks
Kam