Advertisement
Guest User

Untitled

a guest
Jan 6th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. $scope.student = [name: "Joe", grades: "85", info: ""];
  2.  
  3. <?php
  4. $servername = "localhost";
  5. $username = "username";
  6. $password = "password";
  7. $dbname = "myDB";
  8.  
  9. // Create connection
  10. $conn = new mysqli($servername, $username, $password, $dbname);
  11. // Check connection
  12. if ($conn->connect_error) {
  13. die("Connection failed: " . $conn->connect_error);
  14. }
  15. //read the json file contents
  16. $jsondata = file_get_contents("php://input");
  17.  
  18. //convert json object to php associative array
  19. $data = json_decode($jsondata, true);
  20.  
  21. $studentname = $data['studentname'];
  22. $stuedentgrades = $data['stuedentgrades'];
  23. $studentinfo = $data['studentinfo'];
  24.  
  25. $sql = "INSERT INTO students (name, grades, info)
  26. VALUES ('$studentname', '$stuedentgrades', '$studentinfo')";
  27.  
  28. if ($conn->query($sql) === TRUE) {
  29. echo "New record created successfully";
  30. } else {
  31. echo "Error: " . $sql . "<br>" . $conn->error;
  32. }
  33.  
  34. $conn->close();
  35. ?>
  36.  
  37. Undefined index: info
  38.  
  39. `if(isset($_POST('info'))){
  40.  
  41. $info= $data['info'];
  42. }else{
  43. echo "NOOOOOOOOOO";
  44. } `
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement