barbs75 Posted February 21, 2008 Share Posted February 21, 2008 Hi guys, STILL trying to sort out my login/register script. At the moment i am trying to include a form helper, where errors appear on my form rather than on another page away from the form. I know i can store an error in a session and then check if the session is set on form page, so if it is, then output an error. But the problem i am having is grasping how i would present my errors on my page?? I would ideally like a warning box at the top, saying what errors have occurred, and then have a flag next to each label to show the user where the error is, i have looked at an example here http://kalsey.com/simplified/form_errors/ The problem is, it doesnt have much validation, and using this code, im not sure how i would implement my validation i have and whether it is better to have the validation on a separate processing page or all on one page with the form?!?! So what i was trying to do was store each error within an array, and then pass that array in a session, then feed each array element(error) into a list on my form, if that makes sense? here is my code, it might help to take a look at it register.php <?php //create session session_start(); ?> <!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> <?php if (isset($_SESSION['error_storage'])) { echo "<h3>You have an error</h3>"; } ?> <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 <?php session_start(); //create error array to store errors $errorcount = 0; $errorarray = array(); $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']; $encryptusername=md5($_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); $errorcount=1; $errorarray['username'] = "I'm sorry but the username you specified has already been taken. Please pick another one."; //exit(); } //checking if passwords match if ($encryptpass != $encryptpass2) { $errorcount=1; $errorarray['password'] = "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){ $errorcount=1; $errorarray['usernamelength'] = "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){ $errorcount=1; $errorarray['entries'] = "You didn't fill in a required field."; } //checking for acceptance of terms and conditions if(!isset($termsConditions)){ $errorcount=1; $errorarray['termsconditions'] = "Please read and accept our terms and conditions by ticking the appropriate box, thankyou"; } //if there is an error, then output the error, store it in a session and exit program //else carry on with registration and enter data into database table if ($errorcount==1) { echo $errorarray['entries']; //store session data for errors $_SESSION['error_storage']=$errorarray; echo "the stored error session is =". $_SESSION['error_storage']; //exit(); //header('Location: register.php'); } else { $sql="INSERT INTO customer (username,encryptusername,title,surname,forename,email,encryptpass,password,membership,consent1,consent2) VALUES ('$username','$encryptusername','$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()); } 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()); //header('Location: register_success.html'); } ?> please help me out with this, going out of my mind!!! cheers Craig Link to comment https://forums.phpfreaks.com/topic/92300-can-you-store-an-array-in-a-session-help/ Share on other sites More sharing options...
deansatch Posted February 21, 2008 Share Posted February 21, 2008 you shouldn't post your database login details. Link to comment https://forums.phpfreaks.com/topic/92300-can-you-store-an-array-in-a-session-help/#findComment-472914 Share on other sites More sharing options...
barbs75 Posted February 21, 2008 Author Share Posted February 21, 2008 ok, i will take the code out... do you know if you can store an array in a session variable at all?? cheers Link to comment https://forums.phpfreaks.com/topic/92300-can-you-store-an-array-in-a-session-help/#findComment-472919 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.