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);
- date_default_timezone_set('Europe/London');
- $date = new DateTime();
- $dateString = $date->format('d-m-Y H:i');
- $num = 1;
- $test = "test";
- 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)) { //already present in the DB
- updateArchive('$num', '$desiredName', '$test', '$dateString');
- $row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC);
- $location = $row['Location'];
- $updateQuery = "UPDATE location SET Location = '$desiredLocation', UpdateTime = '$dateString' WHERE StudentNo = '$desiredName'";
- sqlsrv_query($conn, $updateQuery);
- echo $desiredName, " location changed to ", $desiredLocation;
- } else { //not yet added
- $insertQuery = "INSERT INTO location (StudentNo, Location, UpdateTime) VALUES ('$desiredName', '$desiredLocation', '$dateString')";
- 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);
- function updateArchive($num, $desiredName, $test, $dateString)
- {
- $archiveQuery = "INSERT INTO history (ID, StudentNo, Location, UpdateTime) VALUES ('$num', '$desiredName', '$test', '$dateString')";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement