Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <? php
- $server = 'SQL2008.net.dcs.hull.ac.uk';
- $connectionInfo = array("Database"=>"rde_504507");
- $conn = sqlsrv_connect($server,$connectionInfo);
- if ($_POST)
- {
- $desiredName = $_POST['name'];
- $desiredLocation = $_POST['location'];
- $locationQuery = "SELECT StudentNo, Location, UpdateTime FROM location WHERE StudentNo='$desiredName'";
- $results = sqlsrv_query($conn, $locationQuery, array($desiredName));
- if(sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC))
- {
- $updateQuery = "UPDATE location SET Location = '$desiredLocation' WHERE StudentNo = '$desiredName'";
- sqlsrv_query($conn, $updateQuery);
- echo $desiredName, " location changed to ", $desiredLocation;
- }
- else
- {
- $insertQuery = "INSERT INTO location (StudentNo, Location, UpdateTime) VALUES ('$desiredName', '$desiredLocation', '00')";
- sqlsrv_query($conn, $insertQuery);
- echo $desiredName, " added to the database at ", $desiredLocation;
- }
- }
- //
- else
- {
- $desiredName = $_GET['name'];
- $locationQuery = "SELECT StudentNo, Location, UpdateTime FROM location WHERE StudentNo='$desiredName'";
- $results = sqlsrv_query($conn, $locationQuery, array($desiredName));
- if($results)
- {
- $row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC);
- echo $desiredName;
- echo " is at ";
- echo $row['Location'];
- echo " at ";
- echo $row['UpdateTime'];
- }
- else
- {
- echo "No user found";
- }
- }
- sqlsrv_close($conn);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement