jquery - Insert data in MYSQL using ajax and php -
This is my html / ajax / jquery and php files. I have to enter the data in the database but the data is not inserted into my database
& lt; Html & gt; & Lt; Top & gt; & Lt; Script src = "http://code.jquery.com/jquery-1.9.1.js" & gt; & Lt; / Script & gt; & Lt; Script src = "http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js</script>lt; add scripts & gt; function () {$ (" # register (Required), Budget: {Required}, Budget: {Required: True}}, Budget: "Required" Message: {Name: "Please enter your name", email: "Please enter a valid email address", Phone: "Please enter a valid phone number", budget: "Please select budget",} Submit Handler: Function (Form) {// Warning ("Success") $ AZ ({url: "insert2.php", type: "post", success: function (response) {warning ("save data:" + response)}})}}}}}}} & lt; / script & Gt; & lt; / head & gt; & lt; body & gt; & lt; form action = "" method = "post" id = "register-form" & gt; & lt; div class = "label" Gt; & lt; / div & gt; & lt; input type = "text" id = input type = "text" id = "email" name = "email" /> gt; & lt; br / & gt; div Class = "label" & gt; phone number gt; & Lt; Br / & gt; & Lt; Div class = "label" & gt; Budget & lt; / Div & gt; & Lt; Select ID = "Budget" name = "budget" & gt; & Lt; Option value = "" & gt; Select & lt; / Options & gt; & Lt; Option value = "1" & gt; 0-100 & lt; / Options & gt; & Lt ;! - Value in the first option = "" - & gt; & Lt; Option value = "2" & gt; 100-200 & lt; / Options & gt; & Lt; Option value = "3" & gt; 200-300 & lt; / Options & gt; & Lt; / Select & gt; & Lt; Br / & gt; & Lt; Div style = "margin-left: 140px;" & Gt; & Lt; Input type = "submit" onclick = "add ()" name = "submit" /> & Lt; / Div & gt; & Lt; / Form & gt; & Lt; / Body & gt;
This is my html / ajax / jquery and php files. I would have to enter the data in the database but the data is not included in my database.
& lt ;? Php $ con = mysqli_connect ("xxxxxxxx", "xxx", "xx", "xx"); If (mysqli_connect_errno ()) {echo "failed to connect to MySQL:". Mysqli_connect_error (); } $ Sql = "Include form (name, email, phone) values ('$ _POST [name]', '$ _ POST [email]', '$ _ POST [phone]')"; If mysqli_query ($ con, $ sql) (die ('error:'. Mysqli_error ($ con))} "added 1 record" echo; mysqli_close ($ thief);? & Gt; <
Data: $ to pass form data using pre> ('# Register-Form'). Serialize (), Try this code
$. Ajax ({url: "insert2.php Serialize (), success: function (response) {warning ("save data:" + response)}}); < / Pre>
Comments
Post a Comment