Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. <?php
  2.  
  3. // Importing DBConfig.php file.
  4. include 'DBConfig.php';
  5.  
  6. // Connecting to MySQL Database.
  7. $con = mysqli_connect($HostName,$HostUser,$HostPass,$DatabaseName);
  8.  
  9. // Getting the received JSON into $json variable.
  10. $json = file_get_contents('php://input');
  11.  
  12. // decoding the received JSON and store into $obj variable.
  13. $obj = json_decode($json,true);
  14.  
  15.  
  16. $S_Name = $obj['nombre'];
  17.  
  18.  
  19. $S_Class = $obj['clase'];
  20.  
  21.  
  22. $S_Phone_Number = $obj['telefono'];
  23.  
  24. $S_Email = $obj['email'];
  25.  
  26. // Creating SQL query and insert the record into MySQL database table.
  27. $Sql_Query = "insert into DetalleEstudiantes (nombre,clase,telefono,email) values ('$S_Name','$S_Class','$S_Phone_Number','$S_Email')";
  28.  
  29.  
  30. if(mysqli_query($con,$Sql_Query)){
  31.  
  32. // If the record inserted successfully then show the message.
  33. $MSG = 'Record Successfully Inserted Into MySQL Database.' ;
  34.  
  35. // Converting the message into JSON format.
  36. $json = json_encode($MSG);
  37.  
  38. // Echo the message.
  39. echo $json ;
  40.  
  41. }
  42. else{
  43.  
  44. echo 'Try Again';
  45.  
  46. }
  47. mysqli_close($con);
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement