Advertisement
madhulika91

The PHP file

Jul 11th, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1. <?php
  2. header('Content-type: application/json');
  3. header('Access-Control-Allow-Origin: *');
  4. $server = "localhost";
  5.  
  6. $username = "root";
  7.  
  8. $password = "";
  9.  
  10. $database = "jqueryex";
  11.  
  12. $con = mysql_connect($server, $username, $password);
  13. if($con) { echo "Connected to database!"; }
  14. else { echo "Could not connect!"; }
  15.  
  16. mysql_select_db($database, $con);
  17.  
  18. $topost =  file_get_contents('php://input');
  19. $thedata=json_decode($topost, true);
  20. print_r($thedata);
  21.  
  22. $id = $thedata['id'];
  23. $name = $thedata['name'];
  24. $Address = $thedata['Address'];
  25.  
  26.     $sql = "INSERT INTO sample (id, name, Address) ";
  27.     $sql .= "VALUES ($id, '$name', '$Address')";
  28.     if (!mysql_query($sql, $con)) {
  29.         die('Error: ' . mysql_error());
  30.     } else {
  31.         echo "Comment added";
  32.     }
  33.    
  34.     mysql_close();
  35. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement