PRodgers4284 Posted February 11, 2008 Share Posted February 11, 2008 I have an edit form to allow users to edit their user account once they are logged in to my website, i can get it edit record fine but im trying to add some validation to the form to stop them editing the form and adding incorrect data, i cant same to get it to work properly. I am using the validation i have used for the registration part of the website and it works fine, just cant same to get it to work properly for the edit account form, ive tried to get it to work with the forename field atm. i have the following code: <?php $error_stat = 0; $forename_message = ''; //Forename check) if (empty($forename)) { //Set the error_stat to 1, which means that an error has occurred $error_stat = 1; //Set the message to tell the user to enter a username $forename_message = '*Please enter your forename*'; } else if (ctype_digit($forename)) { $error_stat = 1; $forename_message .= '*Invalid forename*'; } else if ( preg_match( '/\W/', $forename)){ $error_stat = 1; $forename_message = '*Invalid forename, letters only, no spaces*'; } $forename = $_POST['forename']; $forename = trim($forename); if (strlen($forename) > 12){ $error_stat = 1; $forename_message = '*The forename must be 12 characters or less*'; } if ($error_stat == 0) { mysql_query("UPDATE users SET username='" . $_POST["username"] . "',forename='" . $_POST["forename"] . "',surname='" . $_POST["surname"] . "',email='" . $_POST["email"] . "',mobile='" . $_POST["mobile"] . "',dob='" . $_POST["dob"] . "',location='" . $_POST["location"] . "',about='" . $_POST["about"] . "' WHERE username='" . $_SESSION["username"] . "'"); ?> <br /> <a href="index.php">Back to main page</a> <br /> <br /> <br /> You have successfully updated your account . <?php if (!isset($_POST['submit']) || $error_stat == 1) { } else if $account = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE username='" . $_SESSION["username"] . "'")); { } ?> <form method="post" class="registerform" action=""> <fieldset> <label for="username">Edit Account details</label><fieldset> <p class="edit"> </p> </fieldset> <label for="username">Username:</label> <input name="username" type="text" id="username" value="<?php echo $account["username"]; ?>" /><br /> </fieldset> <fieldset> <label for="forename">Forename:</label> <input name="forename" type="text" id="forename" value="<?php echo $account["forename"]; ?>" /><?php echo "$forename_message";?><br /> </fieldset> <fieldset> <label for="surname">Surname:</label> <input name="surname" type="text" id="surname" value="<?php echo $account["surname"]; ?>" /><br /> </fieldset> <fieldset> <label for="email">Email:</label> <input name="email" type="text" id="email" value="<?php echo $account["email"]; ?>" /><br /> </fieldset> <fieldset> <label for="mobile">Mobile:</label> <input name="mobile" type="text" id="mobile" value="<?php echo $account["mobile"]; ?>" /><br /> </fieldset> <fieldset> <label for="dob">DOB:</label> <input name="dob" type="text" id="dob" value="<?php echo $account["dob"]; ?>" /><br /> </fieldset> <fieldset> <label for="location">Location:</label> <p></p> <select name="location"> <option value="Please Select">Please Select</option> <?php $location_opts = array( "Co.Antrim", "Co.Armagh", "Co.Down", "Co.Fermanagh", "Co.Londonderry", "Co.Tyrone", ); foreach($location_opts as $opt){ $selected = ($account["location"]) == $opt ? " selected=true":""; echo "<option value=\"" . $opt . "\"" . $selected . ">" . $opt . "</option>"; } ?> </select> </fieldset> <hr class="hr_blue"/> <fieldset> Additional Information<br /> <p></p> <fieldset> <label for="about">About you</label> <textarea rows="2" name="about" cols="20" /><?php echo $account["about"]; ?></textarea> <p></p> <fieldset> <p class="submit"> <input type="submit" name="submit" value="Update Account" /> </p> </fieldset> </form> <?php } ?> Quote Link to comment Share on other sites More sharing options...
rameshfaj Posted February 11, 2008 Share Posted February 11, 2008 Please say in brief what do you want to do and what is the problem before posting the code itself. Quote Link to comment Share on other sites More sharing options...
PRodgers4284 Posted February 11, 2008 Author Share Posted February 11, 2008 Please say in brief what do you want to do and what is the problem before posting the code itself. Sorry, i managed to get it sorted, thanks Quote Link to comment 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.