PHP: Check if email already exists when running this code -
i have built simple php form allows user send application using following php code:
if($_server['request_method'] == 'post') { $host = '###'; $username = '###'; $pass = '###'; mysql_connect($host,$username,$pass); mysql_select_db("###"); $status = mysql_real_escape_string($_post['status']); $firstname = mysql_real_escape_string($_post['firstname']); $lastname = mysql_real_escape_string($_post['lastname']); $email = mysql_real_escape_string($_post['email']); $url = mysql_real_escape_string($_post['url']); $query = "insert creathive_applications values (null,'$status','$firstname','$lastname','$email','$url')"; $result = mysql_query($query) or trigger_error(mysql_error().". query: ".$query); }
what want make sure same person doesn't apply twice if email address exists in database show message on form saying "sorry looks you've applied".
here html form, , have added message inside fieldset, need a) show message if email exits or show success message , b) add #membership form url make view jump form on page user see messages. can this? thanks
<form action="" method="post"> <fieldset id="membershipform"> <div id="error"><p>sorry email in use</p></div> <div id="success"><p>thanks application has been sent</p></div> <ul class="clearfix"> <li id="li-status"> <span>i a:</span> <menu> <li><label for="student"><input type="radio" name="status" id="student" checked="checked" value="graduate" /> graduate</label></li> <li><label for="student2"><input type="radio" name="status" id="student2" value="undergraduate" /> undergraduate</label></li> </menu> </li> <li id="li-firstname"> <label for="firstname">first name</label> <input name="firstname" type="text" placeholder="first name" id="firstname" title="first name" /> </li> <li id="li-lastname"> <label for="lastname">last name</label> <input name="lastname" type="text" placeholder="last name" id="lastname" title="last name" /> </li> <li id="li-email"> <label for="email">email address</label> <input name="email" type="text" placeholder="email address" id="email" title="email address" /> </li> <li id="li-url"> <label for="url">url</label> <input name="url" type="text" placeholder="url of you've made" id="url" title="url of you've made" /> </li> <li id="li-buttons"> <input name="submit" type="submit" value="send application ►" title="send application" /> </li> </ui> </fieldset> </form>
do select query before insert validate there aren't entries email already:
select creathive_applications email = $email
if results come back, display message instead of inserting record. can add javascript onload code move form #membershipform if email existed.
Comments
Post a Comment