unable to enter data in mysql using php jquery and ajax -
my mistake friends...below complete code writing jquery php bases register form code. seems code working fine unable enter data in mysql database. please let me know going wrong. below form:
<!doctype html> <html> <head> <link rel="stylesheet" type="text/css" media="all" href="home_style.css"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script> $(document).ready(function(){ $("#ajax-contact-form").submit(function(){ var str = $(this).serialize(); $.ajax( { type: "post", url:"contact.php", data: str, success:function(result) { $("#div1").html(result); } }); return false; }); }); </script> </head> <body> <div id="contact_form"> <form id="ajax-contact-form" name="contact" action=""> <fieldset> <div class="field_container">first name:</label> <input type="text" name="cust_firstname" id="firstname" maxlength="50" onblur="fnamevalidation()" style="width: 250px; height: 30px"; /> <div class="field_container">last name:</label> <input type="text" name="cust_lastname" id="lastname" maxlength="50" onblur="lnamevalidation()" style="width: 250px; height: 30px"; /> <div class="sex_check" > <input type="radio" name="cust_sex" type="radio" value="m" /> male <input type="radio" name="cust_sex" type="radio" value="f" /> female <hr class="line_break"> <div class="field_container">email:</label> <input type="text" name="cust_email" id="email" maxlength="100" onblur="emvalidation()" style="width: 250px; height: 30px"; /> <div class="field_container">password:</label> <input type='password' name='cust_password' id='password' maxlength="12" onblur="pwordvalidation()" style="width: 250px; height: 30px"; /> <div class="field_container">confirm password:</label> <input type='password' name='cust_password2' id='confirmpassword' maxlength="12" onblur="cpwordvalidation()" style="width: 250px; height: 30px"; /> <input class="button" type="submit" name="submit" value="register"> </fieldset> </form> </div> <div id="div1"> </div> </body> </html>
and contact.php is
<?php ob_start(); session_start(); require_once("config.php"); $cust_firstname = stripslashes($_post['cust_firstname']); $cust_lastname=stripslashes($_post['cust_lastname']); $cust_sex=$_post['cust_sex']; $cust_email=stripslashes($_post['cust_email']); $cust_password=stripslashes($_post['cust_password']); $cust_password2=stripslashes($_post['cust_password2']); // values form if(isset($_post['submit'])) { // insert data mysql $res = mysql_query("select * register cust_email = '$cust_email'"); if (mysql_num_rows($res)>0) { echo 'that email registered'; exit; } mysql_query("insert register (`cust_firstname`,`cust_lastname`, `cust_sex`, `cust_email`, `cust_password`) values ('$cust_firstname', '$cust_lastname', '$cust_sex', '$cust_email', '$cust_password')"); $_session['valid_user'] = $cust_email; } echo $cust_firstname; echo $cust_lastname; echo $cust_sex; echo $cust_email; echo $cust_password; echo $cust_password2; ?>
you should remove code in php file says if(isset($_post['submit']))
. one, button name 'submit' (with lowercase s) , two, variable not send never true. should work. recommend @ html markup. totally invalid.
Comments
Post a Comment