barbs75 Posted February 18, 2008 Share Posted February 18, 2008 Hi Guys, At the moment, i have a register.html page which is a register form which when submitted, directs to register_process.php which does all the php to validate the entries, and throw out errors if needed and output a registration complete message to the user and then redirect them to a member screen. The question i want to ask is rather than having errors such as "Username already taken" to appear on register_process.php page, can i have the errors appear next to my username field on my form on register.html?? much like all professional websites do?? What is the procedure for this? do i have to include my form and my php script all on one page?? Please help, any suggestions will be greatly received I have included my code below, and the url to my website is www.go4home.co.uk Thankyou Craig register.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" type="text/css" href="Style1.css" /> <title>Go4home.co.uk - Find your dream property, or advertise your house for sale on the property market on go4home.co.uk</title> <meta name="Description" content="Find your dream property online, Search for any property for sale in a range of areas in the UK with go4home" /> <meta name="Keywords" content="Find a property, find property, find property in UK, search for a property, Property up for sale, find property up for sale, Property market, Advertise your home to sell, go4home.co.uk, go4home" /> </head> <body> <div id="mainContainer"> <div id="container-Content"> <div id="content-TopContent"> <div id="TopBar"> <div id="Logo"><img src="Images/Go4Home-logo.jpg" alt="Go4home.co.uk" width="201" height="39" /></div> <div id="myProfile"></div> <div id="Login"><a href="login_form.html">login</a></div> <div id="NotRegisteredText"><a class="blue" href="register.html">Not Registered?</a></div> </div><!--End of TopBar --> <ul id="navigationMenu"> <li class="HomeButton"><a href="index.html"></a></li> <li class="SearchButton"><a href="Construction Page.html"></a></li> <li class="MoneyMarketButton"><a href="Construction Page.html"></a></li> <li class="GoBuyButton"><a href="Construction Page.html"></a></li> <li class="GoSellButton"><a href="Construction Page.html"></a></li> <li class="HelpButton"><a href="Construction Page.html"></a></li> </ul> </div><!--End of content-Topcontent --> <div id="content-centrecontent"> <br /> <h2 class="shadow">Register</h2> <br /> <p class="centreContent">Already Registered with us? If you are already a member of go4home.co.uk, then please<br> sign in. if not, then please fill in our easy-to-fill form below to join!</p> <p class="centreContent">After registering, we will send you an email, to confirm your details</p> <div id="submitCustomerForm"> <FORM ACTION="register_process.php" METHOD="POST" NAME="contact_form"> <TABLE width="572"> <TR> <TD height="35" colspan="2"><h3>Your Details</h3></TD> <TD></TD> <TD></TD> </TR> <TR> <TD colspan="3"><span class="asterix">*</span> Indicates a required field</TD> <TD></TD> </TR> <TR> <TD></TD> <TD width="187">Your Username:<span class="asterix"> *</span><br /><span class="textSmallGreen">(letters and numbers only)</span></TD> <TD width="27"></TD> <TD width="318"> <input class="fade" name="username" type=text size="50" maxlength="50"></TD> </TR> <TR> <TD></TD> <TD>Your Title:</TD> <TD></TD> <TD><label> <select class="fade" name="titleList" id="titleList"> <option class="fade">--Please Select--</option> <option class="fade" value="Mr">Mr</option> <option class="fade" value="Miss">Miss</option> <option class="fade" value="Mrs">Mrs</option> <option class="fade" value="Ms">Ms</option> </select> </label></TD> </TR> <TR> <TD></TD> <TD>Your Surname: <span class="asterix">*</span></font></TD> <TD></TD> <TD> <input class="fade" name="surname" type=text size="50" maxlength="15"></TD> </TR> <TR> <TD></TD> <TD>Your Forename: <span class="asterix">*</span></TD> <TD></TD> <TD> <input class="fade" name="forename" type=text size="50" maxlength="15"></TD> </TR> <TR> <TD></TD> <TD>Email Address: <span class="asterix">*</span></font></TD> <TD></TD> <TD><input class="fade" name="email" type=text size="50" maxlength="30"></TD> </TR> <TR> <TD></TD> <TD>Your Password: <span class="asterix">*</span></font></TD> <TD></TD> <TD> <input class="fade" name="password" type=password size="50" maxlength="15"></TD> </TR> <TR> <TD></TD> <TD>Confirm Password: <span class="asterix">*</span><br /><span class="textSmallGreen">(Please re enter password)</span></TD> <TD></TD> <TD> <input class="fade" name="password2" type=password size="50" maxlength="15"></TD> </TR> <TR> <TD></TD> <TD>Your Membership: <span class="asterix">*</span></font></TD> <TD></TD> <TD><input class="fade" name="membership" type=text size="50" maxlength="6"></TD> </TR> <TR> <TD height="27" colspan="4"><span class="divider"><hr /></span></TD> </TR> <TR> <TD colspan="2"><h3>Privacy Settings</h3></TD> <TD></TD> <TD></TD> </TR> <TR> <TD width="20" height="22" align="left"><label> <input name="consent1" type="checkbox" id="Consent1" checked="checked" /> </label></TD> <TD colspan="3" align="left">I will allow further contact in the future from go4home only</TD> </TR> <TR> <TD width="20" height="22" align="right"></TD> <TD colspan="3" align="left"><span class="textSmall">This will include emails on latest promotions and services, our newsletters and other important information. You are ensured of no contact from third party</span></TD> </TR> <TR> <TD height="22" align="left"><label> <input type="checkbox" name="consent2" id="Consent2" /> </label></TD> <TD colspan="3" align="left">I allow for future contact from third party</TD> </TR> <TR> <TD height="22" align="right"></TD> <TD colspan="3" align="left"><span class="textSmall">go4home may share my details with third party organizations who may have relevant products that might be of some interest</span></TD> </TR> <TR> <TD height="22" colspan="4" align="left"><span class="divider"><hr /></span></TD> </TR> <TR> <TD height="22" colspan="4" align="left"><h3>Terms & Conditions</h3></TD> </TR> <TR> <TD height="22" colspan="4" align="left"><label></label> <span class="textSmall">For protection of all our go4home customers, we recommend you take a look at our terms & Conditions</span></TD> </TR> <TR> <TD height="22" align="right"><label> <input type="checkbox" name="termsCond" id="Terms&Conditions" /> </label></TD> <TD colspan="3" align="left">I have read and agree to the go4home terms & Conditions</TD> </TR> <TR> <TD height="22" colspan="4" align="left"><span class="divider"><hr /></span></TD> </TR> <TR> <TD height="45" align="right"></TD> <TD align="left"></TD> <TD align="right"></TD> <TD align="right"><input name="Submit" type="image" src="Images/submitButton.png" /></TD> </TR> </TABLE> </FORM> </div><!--End of submitCustomerForm--> </div><!--End of content-centreContent--> </div><!--End of container-Content--> <div id="footer"> <ul id="footerMenu"> <li><a href="Construction Page.html">Go4home terms & conditions</a></li> <li><a href="Construction Page.html">Accessibility</a></li> <li><a href="Construction Page.html">About Us</a></li> <li><a href="Construction Page.html">Privacy Policy</a></li> <li><a href="Construction Page.html">Contact Us</a></li> </ul> <div id="CopyrightText"></div> </div><!--End of footer --> </div><!--End of mainContainer--> </body> </html> register_process.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Registration Process</title> </head> <body> <?php $con = mysql_connect("localhost","root","12waldron"); //Replace with your actual MySQL DB Username and Password if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("customerhouses_db", $con); //Replace with your MySQL DB Name $username=$_POST['username']; $title=$_POST['titleList']; $surname=$_POST['surname']; $forename=$_POST['forename']; //This value has to be the same as in the HTML form file $email=$_POST['email']; //This value has to be the same as in the HTML form file $encryptpass=md5($_POST['password']); $encryptpass2=md5($_POST['password2']); $password = $_POST['password']; $membership=$_POST['membership']; $consent1=$_POST['consent1']; $consent2=$_POST['consent2']; $termsConditions=$_POST['termsCond']; //checking for existing users in database $checkuser = mysql_query("SELECT username FROM customer WHERE username='$username'"); $username_exist = mysql_num_rows($checkuser); if($username_exist > 0){ unset($username); echo "I'm sorry but the username you specified has already been taken. Please pick another one."; exit(); } //checking if passwords match if ($encryptpass != $encryptpass2) { echo "Im sorry, your passwords do not match, please re enter and try again"; exit(); } //checking username isn't over a certain character length $username = trim($username); if(strlen($username) > 12){ die("Sorry, the username is longer than 12 characters, please shorten it."); } //checking for entry in all fields of form if(!$username || !$surname || !$forename || !$email || !$encryptpass || !$encryptpass2 || !$membership){ die('You didn\'t fill in a required field.'); } //checking for acceptance of terms and conditions if(!isset($termsConditions)){ die('Please read and accept our terms and conditions by ticking the appropriate box, thankyou'); } $sql="INSERT INTO customer (username,title,surname,forename,email,encryptpass,password,membership,consent1,consent2) VALUES ('$username','$title','$surname','$forename','$email','$encryptpass','$password','$membership', '$consent1', '$consent2')"; /*form_data is the name of the MySQL table where the form data will be saved. name and email are the respective table fields*/ //echo $password; //echo $encryptpass; //echo $encryptpass2; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } include("register_success.html"); mysql_close($con); //email user confirmation of registration $yoursite = 'www.go4home.co.uk'; $webmaster = 'Craig Barber website Manager'; $youremail = '[email protected]'; $subject = "You have successfully registered at $yoursite..."; $message = "Dear $forename, you are now registered at our web site. To login, simply go to our web page and enter in the following details in the login form: Username: $username Password: $password Please print this information out and store it for future reference. Thanks, $webmaster"; mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion()); echo "Your information has been mailed to your email address."; ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/91710-login-system-errors-to-appear-on-form-help/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.