Jump to content

Bahman

New Members
  • Posts

    1
  • Joined

  • Last visited

Bahman's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi guys I want to send some data to my php page and in that page insert them to database,but dont work.I think Possibility jqury dont work. this is my code: Connection.php <?php $user="root"; $pass=""; $dsn="mysql:host=localhost;dbname=ajax"; try{ $coonnect=new PDO($dsn,$user,$pass); } catch(PDOException $error){ echo "Unable To connect Server".$error->getMessage(); print_r($e.errorInfo()); } ?> index.php <!doctype html> <html> <head> <script src="jquery-3.1.1.js"></script> <script> $(document).ready(function() { $(".btn").click(function(){ var name=$(".name").val(); var lname=$(".lname").val(); var birth=$(".birth").val(); var btn=true; $.post("ajax.php",{name:name,lname:lname,birth:birth,btn:btn},function(data){ $(".result"); alert("OK"); }); }); }); </script> <div class="result"> </div> </head> <body> <tr><td>name:</td><td><input type="text" class="name"></td></tr> <tr><td>last name:</td><td><input type="text" class="lname"></td></tr> <tr><td>birth:</td><td><input type="text" class="birth"></td></tr> <input type="submit" class="btn" value="ثبت"> </body> </html> ajax.php <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <?php include("connection.php"); if(isset($_POST["btn"])){ if($_POST["name"]!="" && $_POST["lname"]!="" && $_POST["birth"]!=""){ $name=$_POST["name"]; $lname=$_POST["lname"]; $birth=$_POST["birth"]; $sql="INSERT INTO bus (name,lname,birth) VALUES (:name,:lname.:birth)"; global $sql; $result=$coonnect->prepare($sql); $result->bindParam(":name",$name); $result->bindParam(":lname",$lname); $result->bindParam(":birth",$birth); $result->execute(); }else{ echo "Please fill"; } } ?> </body> </html>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.