PHP - Form Validation And Check For Existing Email
I have made a form that asks a user for email, first name, last name, and password. I am using Spry validation tools in Dreamweaver. When I used those only, I did not have a problem. The problem began once I tried to actually check to see if the email was already registered. I have tried changing so many things like what $_POST variable to look for at the beginning, to different db connection arrangements. I am stumped. The only other thing I can think of is that I have the order wrong somehow in the logic. Thanks for the help.
First, here is the form: Code: [Select] Enter Email<?php if($error_email_taken) echo ": $error_email_taken."; ?> <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input name="email" type="text" id="email" value="<?php if($_POST["email"]) echo $_POST["email"]; ?>"> <input name="first" type="text" id="first" value="<?php if($_POST["first"]) echo $_POST["first"]; ?>"> <input name="last" type="text" id="last" value="<?php if($_POST["last"]) echo $_POST["last"]; ?>"> <input name="pass" type="password" class="formText1" id="pass" value="<?php if($_POST["pass"]) echo $_POST["pass"]; ?>"> <input type="submit" name="Submit" value="Submit"></td> </form> And the email verification and insert, which is placed before the opening html tag. Code: [Select] <?php if($_POST['Submit']) { //Check to see if email is registered. $email = $_POST['email']; $dbc=mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $q_1 = "SELECT users_email FROM table WHERE users_email = $email"; $r_1 = mysqli_query($dbc, $q_1); $rows_1 = mysqli_num_rows($r_1); if ($rows_1 == 0) { //If 0, email is not already registered. $new_email = $_POST['email']; } else { $error_email_taken = "This email is already registered."; } //If everything is good, insert the information. if(isset($new_email)) { $first_name = $_POST['first']; $last_name = $_POST['last']; $password = $_POST['pass']; //Insert User information. $q_2 = "INSERT INTO table (users_email, users_first, users_last, users_pass) VALUES ('$new_email', '$first_name', '$last_name', '$password')"; $r_2 = mysqli_query($dbc, $q_2); //Go to new page if form was submitted and information properly inserted. header('Location: new_page.php'); }//End: if($new_email) } //End: if $_POST['submit'] ?> I've simplified it as much as I could. I totally eliminated stuff like a password hash, etc. because I wanted to get it down to the most simple form, so once this gets working, I'll add that other stuff later. Thanks so much again. Similar TutorialsHello, I have looked on the forum, but haven't found the answer to this. I have a basic [name, email, phone, event] web form and want to make sure there person is not submitting twice by doing duplicate check of the mail. I looked at other solutions that suggested setting up unique IDs for each user, but it would be possible for a user to sign up for more then one event. Any info would be helpful. Not a newbie, but not an expert. Hello all. I have seen a few threads that loosely deal with ways to do this, but haven't seen anything yet that speaks to this scenario. I have a page (volunteer_signup.php) that shows events to participate in and it passes some variables to a second page (volunteer.php)which is a form for individuals to enter their credentials and that appends to the event detail passed from the first page. I want to be able to check that their email isn't already associated with this particular event, but it is allowed to be in the database for another event. I wanted to do something like the code below, but don't know how to incorporate that with the form (or in volunteerDB.php) any help would be great. thank you in advance. Code: [Select] $sql_email_check = mysql_query("SELECT email FROM users WHERE email='$email'"); $email_check = mysql_num_rows($sql_email_check); if($email_check > 0) { echo "Email is already in our database. Please enter a different email !! <br />"; } exit(); } current form: Code: [Select] <html> <?php include('dbconfig.php'); $event_id = $_GET['id']; $park = $_GET['park']; $orderdate = $_GET['orderdate']; $description = $_GET['description']; $leader = $_GET['leader']; $hour = $_GET['hour']; $min = $_GET['min']; $ampm = $_GET['ampm']; echo $orderdate; echo "<BR>"; echo $park; echo "<BR>"; echo $description; echo "<BR>"; echo $hour; echo ":"; echo $min; echo $ampm; ?> <body> <form enctype="multipart/form-data" action="volunteerDB.php" method="POST" name="myform"> <table border="1"> <input type="hidden" name="event_id" value=<?php echo $event_id; ?>> <input type="hidden" name="park" value=<?php echo $park; ?>> <input type="hidden" name="orderdate" value=<?php echo $orderdate; ?>> <input type="hidden" name="description" value=<?php echo $description; ?>> <input type="hidden" name="leader" value=<?php echo $leader; ?>> <input type="hidden" name="hour" value=<?php echo $hour; ?>> <input type="hidden" name="min" value=<?php echo $min; ?>> <input type="hidden" name="ampm" value=<?php echo $ampm; ?>> <tr> <td>First Name</td> <td> <input name="firstname" /> </td> </tr> <tr> <td>Last Name</td> <td> <input name="lastname" /> </td> </tr> <tr> <td>Email</td> <td> <input name="email" /> </td> </tr> <tr> <td>Phone</td> <td> <input name="phone" /> </td> </tr> <tr> </tr> </table> <input type="submit" value="Submit" onclick="verify();"> </td> </tr> </form> </body> </html> form feeds to this php page (volunteerDB.php): Code: [Select] <?php include('dbconfig.php'); $event_id = $_POST['event_id']; $park = $_POST['park']; $orderdate = $_POST['orderdate']; $description = $_POST['description']; $leader = $_POST['leader']; $hour = $_POST['hour']; $min = $_POST['min']; $ampm = $_POST['ampm']; $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; $phone = $_POST['phone']; $email_list = $_POST['email_list']; // Make a MySQL Connection mysql_connect("localhost", "$user", "$password") or die(mysql_error()); mysql_select_db("$database") or die(mysql_error()); mysql_query("INSERT INTO volunteer (id, event_id, park, firstname, lastname, email, phone, email_list) VALUES('', '$event_id', '$park', '$firstname', '$lastname', '$email', '$phone', '$email_list') ") or die(mysql_error()); ?> <?php $to = "$email"; $subject = "Trailworker Event Signup Confirmation"; $message = "Hello $firstname! Thank you for signing up to work the $park trailworker event. A crew leader will contact you shortly. Park: $park Date: $orderdate Time: $hour:$min $ampm Description: $description Crew Leader: $leader"; $from = "info@xxxxxxxxxx.com"; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo "Thank you for signing up. You will receive an email shortly letting you know event details and who your crew leader is."; ?> Hey everyone. I hope you can help me getting through this problem, because I have no idea of what else to try. I'm a web designer and sometimes modify Javascript, but my main focus is HTML and CSS, meaning I have no idea how to code in Javascript, but most importantly, how to write something from scratch in PHP. So I designed a form that works pretty well, and integrated a PHP and Javascript script to make it work. This is the form: Code: [Select] <form name="form" id="form" method="post" action="contact.php"> <p>Hello,</p> <p>My name is <input type="text" name="name">, from <input type="text" name="location">, and I'd like to get in touch with you for the following purpose:</p> <p><textarea name="message" rows="10" ></textarea></p> <p>By the way, my email address is <input type="text" name="email" id="email" placeholder="john@doe.com">, and I can prove I'm not a robot because I know the sky is <input type="text" name="code" placeholder="Red, green or blue?">.</p> <p title="Send this message."><input type="submit" id="submit" value="Take care."></p> </form> And this is the script, in an external file called contact.php: Code: [Select] <?php $name = check_input($_REQUEST['name'], "Please enter your name.") ; $location = check_input($_REQUEST['location']) ; $message = check_input($_REQUEST['message'], "Please write a message.") ; $email = check_input($_REQUEST['email'], "Please enter a valid email address.") ; if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) {die("E-mail address not valid");} if (strtolower($_POST['code']) != 'blue') {die('You are definitely a robot.');} $mail_status = mail( "my@email.com", "Hey!", "Hello,\n\n$message\n\nRegards,\n\n$name\n$location", "From: $email $name" ); function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?> <html> <body> <b>Please correct the following error:</b><br /> <?php echo $myError; ?> </body> </html> <?php exit(); } if ($mail_status) { ?> <script language="javascript" type="text/javascript"> alert('Thank you for the message. I will try to respond as soon as I can.'); window.location = '/about'; </script> <?php } else { ?> <script language="javascript" type="text/javascript"> alert('There was an error. Please try again in a few minutes, or send the message directly to aalejandro@bitsland.com.'); window.location = '/about'; </script> <?php } ?> So what it does is this: if everything's OK, it sends an email with "Hey!" as the subject, "[name]" as the sender, "Hello, [message]. Regards, [name], [location]" as the body, and a popup saying the message was delivered appears. If something fails, it outputs the error in a new address, so the user will have to go back to the form and correct the error. What I actually want to happen is this: if everything's OK, a <p> which was hidden beneath the form appears saying the message was delivered, or, alternatively, make the submit button gray out and confirm the message was delivered. I found a script to make this happen, but with "Please wait...", so the user can't resubmit the form. If there's an error, I'd like another <p> which was hidden to appear with the specific error, so there'd be many <p>'s hidden with different IDs. If possible, I'd also like to change the CSS style of the input field, specifically changing the border color to red, so it'd be a change in class for the particular field. -- So in essence, I want the errors and the success messages to output in the same page as the form (without refresh), and a change of class in the input fields that have an error. Thanks in advance, and please let me know if it'll be possible. I am using this a modal window(jBox) - with a web Form in it, that requires the Form (just Name & Email) to be completed and Submitted in order to close the modal window - allowing access to the main page. The Form uses this corresponding ../submit.php which this: if (empty($_POST['name'])|| empty($_POST['email'])){ $response['success'] = false; } else { $response['success'] = true; } echo json_encode($response); where, upon Form > submit, successfully shows 'error' if the Form fields are not populated, and 'success' when the Form fields are populated/submitted.
I'd like the Form to require a proper/valid email address and avoid spam and header injection Any assistance/guidance is appreciated
Hi guys, Trying to ge this to work: function checkEmail($useremail) { if (!preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/" , $useremail)) { return false; $error = '<div id="blackText"><p>Sorry! Please check your email address and try again!<p><p><a href="forumsSignUp.php">Back</a></p></div>'; } return true; //PASSWORD AND OTHER VALIDATION STUFF, blah blah blah } But its just not. Everything works fine if I remove this though. Can anyone suggest an alternative to email address validation? Thanks! i wanting users to be able to update there email address and check to see if the new email already exists. if the email is the same as current email ignore the check. i have no errors showing up but if I enter a email already in the db it still accepts the new email instead of bringing the back the error message. Code: [Select] // email enterd from form // $email=$_POST['email']; $queryuser=mysql_query("SELECT * FROM members WHERE inv='$ivn' ") or die (mysql_error()); while($info = mysql_fetch_array( $queryuser )) { $check=$info['email']; // gets current email // } if($check!=$email){ // if check not equal to $email check the new email address already exists// $queryuser=mysql_query("SELECT * FROM members WHERE email='$email' "); //$result=mysql_query($sql); $checkuser=mysql_num_rows($queryuser); if($checkuser != 0) { $error= "0"; header('LOCATION:../pages/myprofile.php?id='.$error.''); } } cheers Hi guys, im inserting data into the table using drop-down list & multi select list,well it works very well. but i need to make sure i should not insert same StudentID & CourseID twice. here my code for you could anyone tell me pls where should i write code to check existing data? <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("uni", $con)or trigger_error('MySQL error: ' . mysql_error()); $result = mysql_query("SELECT * FROM student") or trigger_error('MySQL error: ' . mysql_error()); echo '<select name="sid">'; while($row = mysql_fetch_array($result)) { echo '<option value="' . $row['StudentID'] . '">' . $row['StudentName'] . '</option>'; } echo '</select>'; // ---------------- ?> </div> <div class="style41" id="Layer7"> <?php $result = mysql_query("SELECT * FROM course") or trigger_error('MySQL error: ' . mysql_error()); echo '<select name ="cid[]" multiple="multiple" size="10">'; while($row = mysql_fetch_array($result)) { echo '<option value="' . $row['CourseID'] . '">' . $row['CourseName'] . '</option>'; } echo '</select>'; mysql_close($con); ?> ------------------------------------ <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("uni", $con)or trigger_error('MySQL error: ' . mysql_error()); if (!empty($_POST['sid']) && !empty($_POST['cid'])) { $ct = 0; $student = $_POST['sid']; foreach ($_POST['cid'] as $key => $course) { $sql = "INSERT INTO take (StudentID, CourseID) VALUES('".mysql_real_escape_string($student)."', '".mysql_real_escape_string($course)."')"; $query = mysql_query($sql) or trigger_error('MySQL error: ' . mysql_error()); if (mysql_affected_rows() > 0){$ct++;} } echo $ct . ' rows added.'; } mysql_close($con); ?> I'm trying to get my php form to send a simple auto responder to the persons email that submitted the form. Something like "Thanks we received your info". I don't know how to integrate that into my existing script. Below are the configurable parts of the php. The form works perfectly ... just want to add the auto respond function. Thanks! _________________________________________________ _________________________________________________ _____ <?php $d = date("m-d-y H:i:s"); /* ************* Begin Configuration ************* */ $relocate = "http://www.xxxxx.com/"; // insert your relocation url here $home = "http://www.xxxxx.com/"; $MOVE_TO_PATH = '/home/content/xxxxx/html/FileUpload/'; $PATH_TO_DIR = 'http://www.xxxxx.com/FileUpload/'; $sender_name = "Order"; $sender_email = "me@xxxxx.com"; $mailheaders = "Content-Type: text/plain; charset=us-ascii\nFrom: $sender_name <$sender_email>\nReply-To: <$sender_email>\nReturn-Path: <$sender_email>\nX-Mailer: PHP"; //$to = "me@xxxxx.com"; $to = "me@xxxxx.com"; $subject = "Order"; $success_block = "<p>Thank you for submitting your information. We will review your information and get back to you within a day or two.</p><br><br>"; /* ************* End Configuration ************* */ if ($send != "false") { mail($to, $subject, $msg, $mailheaders); // mail sent to admin header("Location: $relocate"); } ?> I am working on a web form in PHP which accepts a Paypal Email address from the user. I need to authenticate (validate or check) if the Paypal email address entered is a valid Paypal email account. Please reply. All comments and feedback are welcomed. Thank you! EDIT: sorry - new to posting guidelines - using XAMPP with mysql 5.1.44 (I think this is correct!!) Newbie question he I have successfully created a form that that displays students (based on a selected lesson/group/date) with the ability to enter scores. I'm now trying to set the form up so that if data already exists then it is displayed in the form. Eg: if a member of staff choses group 7AS, lesson 1, 24/09/2010 and another member of staff has entered a score already for one student it shows up in the <select> drop down by using Code: [Select] <option>" . $scorevalue . "</option> I had this working at one point but have made a change somewhere and cannot get it working again! can anyone spot an obvious mistake I am making? The code I am using is as follows: Code: [Select] <input type="hidden" name="tutor" value="<?php echo $_GET["tutor"]; ?>" /> <input type="hidden" name="date" value="<?php echo $_GET["date"]; ?>" /> <input type="hidden" name="lesson" value="<?php echo $_GET["lesson"]; ?>" /> <?php error_reporting(-1); $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("lakeside", $con); $result = mysql_query("SELECT students.admin, students.fname, students.surname, students.tutor FROM students WHERE tutor='$_GET[tutor]' ORDER BY students.tutor, students.surname"); echo "<table class='scores'> <tr> <th>Admin</th> <th>Firstname</th> <th>Surname</th> <th>Tutor</th> <th>Score</th> <th>Code</th> <th>Comment</th> </tr>"; while($row = mysql_fetch_array($result)) { $sqlstatement = "SELECT * FROM scores where admin = '" . $row['admin'] . "' and lesson = '" . $_GET[lesson] . "' and date = '" . $_GET[date] . "' "; $scorevalue = mysql_query($sqlstatement); echo " . $score . "; while($rowvalue = mysql_fetch_array($scorevalue)) { $score = $rowvalue['score']; $comment = $rowvalue['comment']; $code = $rowvalue['code']; } echo "<tr>"; echo "<td>" . $row['admin'] . "</td>"; echo "<td>" . $row['fname'] . "</td>"; echo "<td>" . $row['surname'] . "</td>"; echo "<td>" . $row['tutor'] . "</td>"; echo "<td><select name='score" . $row['admin'] . "' value='{$row['score']}' /> <option>" . $scorevalue . "</option> <option>0</option> <option>1</option> <option>2</option> <option>2.5</option> <option >3</option> <option>3.5</option> <option>4</option> </select> </td>"; Hi, I'm trying to make a form that will submit a customers order into my database. The form it self is no problem and posting it to the database that part I can do, but I want this form to find existing posts in my database as the user inputs information. As an example if I add an ordrer for a customer ordering item numberr "1234" the form will search for item numberr "1234" and print it back to the form before the user submit the form, like "auto finish" the form. So in other words it will search the database "on the fly" for this item and fill it in. Could someone point me in the right direction? Somewhere in the PHP manual or maybe a good tutorial on this topic. Hi guys, I'm having problems integrating Recaptcha into an existing form. I want it all to process on the same page. I took a look on Google and found a pre-existing script which does what I want but I'm still having trouble integrating it with what I already have, form fields and the recaptcha validate seperately. Here's my script so far: before the <html> tag: Code: [Select] <?php session_start(); ?> <?php // DEMO to use reCAPTCHA library on a form // // courtesy Spectrum Nashville // http://www.spectrum-nashville.com // // provide the Public Key and Private Key for your account he define( API_PUBLIC_KEY, '6LeNt84SAAAAAAH0Et-eJpNeuYO-kRXgrpcXML36' ); define( API_PRIVATE_KEY, '6LeNt84SAAAAAMlGWZUEHqFHncRyvaYbI5YdE8BY' ); // // once the keys have been provided above, this demo should work without any further changes to the code below // // include the recaptcha library file here // require_once('recaptchalib.php'); // // the $validated variable will switch to true in the code below if a valid CAPTCHA is submitted (see code below). // do not change this. // $validated = false; ?> <?php //If the form is submitted if(isset($_POST['submit'])) { //Check to make sure that the name field is not empty if(trim($_POST['name']) == '') { $hasError = true; } else { $name = trim($_POST['name']); } //Check to make sure sure that a valid email address is submitted if(trim($_POST['email']) == '') { $hasError = true; } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) { $hasError = true; } else { $email = trim($_POST['email']); } //Check to make sure comments were entered if(trim($_POST['comment']) == '') { $hasError = true; } else { if(function_exists('stripslashes')) { $comment = stripslashes(trim($_POST['comment'])); } else { $comment = trim($_POST['comment']); } } //If there is no error, send the email if(!isset($hasError)) { $emailTo = 'eevansrange@gmail.com'; //Put your own email address here $subject = "Feedback from TEST FORM"; $body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comment"; // $body = "Enquiry type: $enquiry \n\nName: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments"; $headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; mail($emailTo, $subject, $body, $headers); $emailSent = true; } } ?> Within body tag: Code: [Select] <!-- RECAPTCHA START --> <script> // example of using JavaScript variable to provide "theme" control // of the reCAPTCHA element. This entire <script> block is optional. var RecaptchaOptions = { theme : 'blackglass', tabindex : 2 }; </script> <!-- RECAPTCHA END --> <section id="form"> <h2 class="blue">CONTACT ME</h2> <div id="form-holder"> <p class="form-instructions">Need some work doing? Have a comment? Post them below and I'll get back to you asap!</p> <?php if(isset($hasError)) { //If errors are found ?> <p class="errors">Please check you've filled out the fields correctly.</p> <?php } ?> <?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?> <p class="success">Thank you <strong><?php echo $name;?></strong>, your email has been sent.</p> <?php } ?> <?php // see the form below and look for the hidden input named 'validate' to see how this works. This is a nice flag to // indicate to us that the validation should be attempted. The first time a user browses to this page, there will be // no 'validate' variable in the $_POST[] array, so no validation is attempted and no error message will be generated. // // do not change any of this code. // if( $_POST['validate'] === 'yes' ) { $response = recaptcha_check_answer( API_PRIVATE_KEY, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field'] ); if( ! $response->is_valid ) { // // captcha failed -- display the error message // // change this to whatever message you want to display. you could even perform other form validations // and display messages about other required fields, etc., here if you want. // use the CSS in the <head> section above to determine how your error message "box" will appear. // echo '<div id="recaptcha_error_box">The reCAPTCHA failed with this message: '.$response->error.'<br />Please try again.</div>'; // by default now, let the flow-of-control fall back into the <form> below so the user can try again } else { // set $validated to true so we know later in our document not to show the form again // don't change this. $validated = true; // // YOUR CODE HERE.... // // at this point, th form was submitted with valid reCAPTCHA, so go do whatever you wanted to do. // for the demo, we'll just echo back the values from the form. // // you could also send an email message, add or update database records, etc. // ?> <?php } /* end if( ! is_valid ) */ } /* end if($_POST['validate']==='yes') */ ?> <?php if( ! $validated ) { ?> <form class="cmxform" id="commentForm" method="post" border="0" action="<?php echo $_SERVER['PHP_SELF']; ?>#form"><!-- added #form so on submit the page anchors to the form div rather than taking you back to the top of the page --> <?php require_once('recaptchalib.php'); $publickey = "6LeNt84SAAAAAAH0Et-eJpNeuYO-kRXgrpcXML36"; // you got this from the signup page echo recaptcha_get_html($publickey); ?> <!--<input type="submit" />--> <br /> <label class="required" for="name" title="Enter your name"><span>Name</span><input type="text" id="name" name="name" size="50" class="required" value="<?php echo stripslashes(htmlentities($_POST['your_name'])); ?>" /></label> <label class="required" for="email" title="Enter your email"><span>Email</span><input type="text" id="email" name="email" size="50" class="required" value="<?php echo stripslashes(htmlentities($_POST['your_email'])); ?>" /></label> <label class="required" for="comment" title="Enter your comments" size="50" value="<?php echo stripslashes(htmlentities($_POST['comment'])); ?>"> <span>Comments</span><textarea name="comment" rows="5" cols="50" class="required"></textarea> </label> <!-- CAPTCHA START --> <?php echo recaptcha_get_html(API_PUBLIC_KEY); ?> <!-- CAPTCHA END --> <input type="hidden" name="validate" value="yes" /> <!--<input type="submit" value="Try It" />--> <label for="submit" class="nocontent"><input class="submit" type="submit" name="submit" value="Try It" title="Send form" />Items marked <img src="images/required-2.png" width="12" height="12" alt="required field" /> are required fields</label> <!-- need to include the name tag =submit above for the form to process and send the email --> <!-- class="nocontent" - commmented out of above label --> </form> <?php } /* end if( ! $validated ) */ ?> </div> </section> <!-- client-side validation --> <script type="text/javascript"> jQuery(function(){ // Grab each form element jQuery("label[title]").each(function(){ jQuery(this).append("<div class=\"infopop\">"); titletext = jQuery(this).attr("title"); jQuery(this).removeAttr("title"); jQuery(".infopop",this).css({opacity:0}).html(titletext); jQuery("input",this).focus(function(){ // Mouseover doFocus(this); }).blur(function(){ // MouseOut doBlur(this); }); /* ADDED TO show errors for textarea */ jQuery("textarea",this).focus(function(){ // Mouseover doFocus(this); }).blur(function(){ // MouseOut doBlur(this); }); }); }); function doFocus(obj) { jQuery(obj).addClass("active").parents("label").addClass("active").find(".infopop").animate({opacity:1,left:492},500); } function doBlur(obj) { if (validate(obj)) { isGood(obj); } } function reportErr(obj, message) { jQuery(obj).addClass("error").parents("label").removeClass("isgood").addClass("required").addClass("error").find(".infopop").html(message).addClass("errorpop").animate({opacity:1,left:492},500); } function isGood(obj) { jQuery(obj).removeClass("error").removeClass("active").parents("label").addClass("isgood").removeClass("error").removeClass("active").find(".infopop").removeClass("errorpop").animate({opacity:0,left:513},500); } function validate(obj) { mask = jQuery.extend({textfieldmask: /^[a-z\.\s-]{5,}$/i,emailmask: /^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/i,commentsboxmask: /^[a-z\.\s-]{5,}$/i}); errmsg = jQuery.extend({textfielderr:"5 or more letters",emailerr:"Invalid address",matcherr: "Must match",commenterr: "5 or more letters"}); var masktouse = null; var mustmatch = null; switch(obj.name) { case "name": masktouse="textfieldmask"; errtouse="textfielderr"; break; case "email": masktouse="emailmask"; errtouse="emailerr"; break; case "comment": masktouse="commentsboxmask"; errtouse="commenterr"; break; } // Check that the element is a required field before validating against it. if(jQuery(obj).parents("label").hasClass("required") && masktouse) { // Set up a quick way of accessing the object we're validating pointer = jQuery(obj); // Test the value of the field against the Regular Expression if (mask[masktouse].test(pointer.val())) { // The field validated successfully! // Check to see if the field needs to match another field in the form if (mustmatch) { // It does need to match, so grab the object it needs to match matchobj = jQuery("#"+mustmatch); if (matchobj.val()!='' && matchobj.val()!=pointer.val()) { // The fields don't match, so report an error on both of them reportErr(obj,errmsg["matcherr"]); reportErr(matchobj,errmsg["matcherr"]); } else { // Either the fields match, or the other field hasn't been completed yet // If the other field has been completed, call the isGood function to clear any error message showing if (matchobj.val()!='') { isGood(matchobj);} return true; } } else { // No match is required, so return true - validation passed! return true; } } else { // The field failed to validate against the Regular Expression reportErr(obj,errmsg[errtouse]); return false; } } else { // This isn't a required field, so we won't validate it against anything return true; } } </script> Any help would be much appreciated MK Hi guys, I've spent quite a bit of time searching the site and have a good start - hoping for some help. I run a hockey league and have a database that keeps our stats. Regular stats page is here - http://okchockey.com/stats/stats.php I need a web form that can update existing records in the database. Maybe I am going thru this the wrong way - please let me know. I know there's a better way than my current version. Basically I have a table that has fields of Week, Jersey, Name, Goals, Assists, Points, and Penatly_Min. Again - excuse the newbie-ness - what I did is have a record for each player for each week. I already pre-created a record for each player for each week. I just need a web form that will update these existing records. I already created one that can add new records but I am having a tough time creating one to update existing ones. I'd like to be able to select the week (week 1-10) then select a player and update his stats for that particular week. Hopefully this makes sense. If anyone has some sample code I can look at I'd sure appreciate it. Really struggling trying to teach myself PHP Hi, I have a basic form that lets people enter details Code: [Select] <form action="welcome.php" method="post"> Name: <input type="text" name="fname" /> Second name: <input type="text" name="sname" /> <input type="submit" /> </form> And the standard insert in sql command. Im now looking to add a image uplad field the the same form. I have tried several methods off the internet but i cant get any to work. I would like the form to upload the image into the directory '../images' and then save the path to the file in the database, e.g. 'images/picture.jpg'. Can anyone point me in the right direction please. Im guessing i will have to use the file input type but i cant get any of it to work. Thanks does anyone have code for checking to make sure an email address is typed in correct Hey guy, I have a form where I want to validate if the check boxes have been checked or not and store that in a session. If a box is not selected I want an error message to echo. With what I've done so far, if a box is selected the form works but if one is not selected my error message does not show and I get an undefined Index Notice. Can anyone tell me where I'm going wrong. Page 1- form <form action="processPage7.php" method="post"> <br /> <p>Check the times you are most likely to have available:</p> <input type="checkbox" name="days[]" value="Evenings" <?php if(isset($_POST['days']) == 'Evenings') echo 'checked' ?>> Weekday evenings<br /> <input type="checkbox" name="days[]" value="Weekdays" <?php if(isset($_POST['days']) == 'Weekdays') echo 'checked' ?>> Week Days<br /> <input type="checkbox" name="days[]" value="Weekends" <?php if(isset($_POST['days']) == 'Weekends') echo 'checked' ?>> Weekend Days<br /> </div><br /><br /> <p><input type="submit" value="Next Page" /></p><input type="reset" value="Reset" /> </form> Page 2- <?php session_start(); if($_SERVER['REQUEST_METHOD']== 'POST'){ $valid_form = TRUE; // NO PROBLEMS if(!isset($_POST['days'])){ echo "Error, no time selected. Please go back and select a time."; }else{ $_SESSION['days'] = $_POST['days']; } if($valid_form == TRUE){ header('Location: FormProcess.php'); } } ?> And Page 3 <?php session_start(); $days = $_SESSION['days']; $chkResults = $days; for ($i = 0;$i<=count($chkResults)-1;$i++){ echo "<p>". $days[$i]; } ?> Thanks in advance. I have an existing GET form that I use and want to write to a MYSQL table everytime a user uses that form. Code: [Select] <FORM ACTION="https://someurl.com" METHOD=GET> Would the easiest to be a javascript function that uses the onclick event? What would be the best way to continue to pass the user along while capturing data and writing that to a MYSQL table. Thanks! Hi all, I was just thinking that it might be possible to find out if someone read an email. If someone might want to share his thoughts on the following I would be really happy The idea i had is that instead of requiring a receipt to sign, which most free email providers don't provide. Instead send an html email with an external image with a unique name for the receiver. Ones the receiver opens the email it requests the image. This probbably isn not fool proof since someone can view in plain text, but it might be a nice thought. Is there maybe a way to track how often an image is requested and perhaps from where (IP or so). Which might not be usefull since it will come from a general email provider. This idea just popped up for me and i thought it could be nice to chat about it. If someone knows a better tracker way which is still customer friendly I would love to know : ) The idea is that in some cases it might me nice to remind someone if they didn't opn an email. Cheers! I am trying to check if email already in DB. This is what I have so far and does not work. Code: [Select] if($email){ // checking user input $check_email=mysql_query("SELECT * FROM userlist WHERE email ='".$email."' "); $get_email=mysql_fetch_array($check_email); $existsmail=$get_email['email']; if($email == $existsmail){ $resultado = "Email address already exists!"; } if($email != $existsmail){ $resultado = "Your Account was created successfully! You may now login."; $date=getdate(); $insert=mysql_query("INSERT INTO userlist VALUES ('', '$name', '$phone', '$fax', '$company_name', '$billing_address', '$billing_city', '$billing_state', '$billing_zip_code', '$email', AES_ENCRYPT('$mysecretkey''password') ,now())"); }else{ $resultado = ""; } echo $resultado; } Thanks in advance. All, In my registration script I am trying to check if an email address already exists (yawn I know), and I am stuck. The code highlighted in bold is where I want to check if the email exists (notice that form checking is done above that, including sorting out the email address that the user enters) and if it doesnt insert data into the table. Trouble is that on loading the page it simply states the 'already submitted' error before an email is even entered into the form: Code: [Select] if(isset($_POST['name']) && !empty($_POST['name']) AND isset($_POST['email']) && !empty($_POST['email']) AND ($_POST['password']) && !empty($_POST['password'])){ $name = mysql_escape_string($_POST['name']); // Turn our post into a local variable $email = mysql_escape_string($_POST['email']); $password = mysql_escape_string($_POST['email']);// Turn our post into a local variable } $name = mysql_escape_string($_POST['name']); $email = mysql_escape_string($_POST['email']); $password = mysql_escape_string($_POST['password']); if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){ // Return Error - Invalid Email $msg = 'The email you have entered is invalid, please try again.'; }else{ // Return Success - Valid Email $msg = 'Your account has been made, <br /> please verify it by clicking the activation link that has been sent to your email.'; } $hash = md5( rand(0,1000) ); // Generate random 32 character hash and assign it to a local variable. // Example output: f4552671f8909587cf485ea990207f3b [b]$emailCheck = mysql_query("SELECT email FROM users WHERE email = '".$email."'"); if (mysql_num_rows($emailCheck) > 0) { echo "already submitted"; } else {[/b] // We have a match, activate the account mysql_query("INSERT INTO users (username, password, email, hash) VALUES( '". mysql_escape_string($name) ."', '". mysql_escape_string(md5($password)) ."', '". mysql_escape_string($email) ."', '". mysql_escape_string($hash) ."') ") or die(mysql_error()); Thanks in advance, G |