Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. <? php
  2. $server = 'SQL2008.net.dcs.hull.ac.uk';
  3. $connectionInfo = array("Database"=>"rde_504507");
  4. $conn = sqlsrv_connect($server,$connectionInfo);
  5.  
  6. if ($_POST)
  7. {
  8. $desiredName = $_POST['name'];
  9. $desiredLocation = $_POST['location'];
  10. $locationQuery = "SELECT StudentNo, Location, UpdateTime FROM location WHERE StudentNo='$desiredName'";
  11. $results = sqlsrv_query($conn, $locationQuery, array($desiredName));
  12.  
  13. if(sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC))
  14. {
  15. $updateQuery = "UPDATE location SET Location = '$desiredLocation' WHERE StudentNo = '$desiredName'";
  16. sqlsrv_query($conn, $updateQuery);
  17. echo $desiredName, " location changed to ", $desiredLocation;
  18. }
  19. else
  20. {
  21. $insertQuery = "INSERT INTO location (StudentNo, Location, UpdateTime) VALUES ('$desiredName', '$desiredLocation', '00')";
  22. sqlsrv_query($conn, $insertQuery);
  23. echo $desiredName, " added to the database at ", $desiredLocation;
  24.  
  25. }
  26.  
  27. }
  28.  
  29. //
  30. else
  31. {
  32. $desiredName = $_GET['name'];
  33. $locationQuery = "SELECT StudentNo, Location, UpdateTime FROM location WHERE StudentNo='$desiredName'";
  34.  
  35. $results = sqlsrv_query($conn, $locationQuery, array($desiredName));
  36.  
  37. if($results)
  38. {
  39. $row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC);
  40. echo $desiredName;
  41. echo " is at ";
  42. echo $row['Location'];
  43. echo " at ";
  44. echo $row['UpdateTime'];
  45. }
  46. else
  47. {
  48. echo "No user found";
  49. }
  50.  
  51.  
  52. }
  53. sqlsrv_close($conn);
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement