Jump to content

Help PHP Coding - thanks


kam1313

Recommended Posts

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

 

 

 

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.