kam1313 Posted December 18, 2009 Share Posted December 18, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/185580-help-php-coding-thanks/ Share on other sites More sharing options...
Adam Posted December 18, 2009 Share Posted December 18, 2009 May want to quickly remove the MySQL details you've just posed. Quote Link to comment https://forums.phpfreaks.com/topic/185580-help-php-coding-thanks/#findComment-979753 Share on other sites More sharing options...
cags Posted December 18, 2009 Share Posted December 18, 2009 Give your 'cousin' this link. Quote Link to comment https://forums.phpfreaks.com/topic/185580-help-php-coding-thanks/#findComment-979754 Share on other sites More sharing options...
Deoctor Posted December 18, 2009 Share Posted December 18, 2009 i would surely like to help you out. but there are some flaws in ur code.. u are checking the email validation after u are entering the details in the sql tables. so even if he gives the wrong email id it will get stored in database. and the other question i dont understand is what u want us to solve in this..?? is the code not working/working or any errors.. if u want any help please give all the details of ur need. also use the code tags... Quote Link to comment https://forums.phpfreaks.com/topic/185580-help-php-coding-thanks/#findComment-979755 Share on other sites More sharing options...
Adam Posted December 18, 2009 Share Posted December 18, 2009 Surely it would make more sense for your cousin to come and ask? Then when people give feedback and help to work out the solution, he'll learn through the process and won't be just relayed the working code? Quote Link to comment https://forums.phpfreaks.com/topic/185580-help-php-coding-thanks/#findComment-979758 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.