Advertisement
Guest User

Untitled

a guest
Mar 16th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. <?php
  2. $host = 'localhost';
  3. $dbname = 'test';
  4. $username = 'root';
  5. $password = '';
  6.  
  7. try
  8. {
  9. $conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
  10. /* echo "Connected to $dbname at $host successfully.<br/>"; */
  11. }
  12. catch (PDOException $e)
  13. {
  14. echo "<h3>Error:</h3>". $e->getMessage();
  15. }
  16.  
  17.  
  18. $customer_id=addslashes($_GET['customer_id']);
  19.  
  20. $t=time();
  21. $d=date("Y-m-d",$t);
  22.  
  23.  
  24. $sql= "INSERT INTO `test`.`orders` (`customer_id`, `date`) VALUES ('$customer_id', '$d');";
  25.  
  26. $result =$conn->query($sql);
  27. $lastid = $conn->lastInsertId();
  28.  
  29. if($result==1)
  30. {
  31.  
  32. $query = "select * from `orders` where customer_id='$customer_id'";
  33. $result = $conn->query($query);
  34. $dbvalue = $result->fetch(PDO::FETCH_OBJ);
  35. $customer_id=$dbvalue->customer_id;
  36. $date=$dbvalue->date;
  37.  
  38.  
  39. $details = array(
  40. 'status'=>'sucess',
  41. 'message'=>'customer added sucessfully',
  42. 'id' => $lastid,
  43. 'customer_id' => $customer_id,
  44. 'date' => $date,
  45. );
  46.  
  47. echo json_encode($details);
  48. }
  49. else
  50. {
  51. $detail = array(
  52. 'status'=>'unsucess',
  53. 'message'=>'cannot add customer',
  54.  
  55. );
  56.  
  57. echo json_encode($detail);
  58. }
  59. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement