summaryrefslogtreecommitdiffstats
path: root/notFinishedCode/tricode/insertData.php
diff options
context:
space:
mode:
authorRefik Hadzialic2011-09-11 20:52:46 +0200
committerRefik Hadzialic2011-09-11 20:52:46 +0200
commitb42ef6d7bc5b8974e0b88d96170be58a186b652b (patch)
tree3b67741594f6cdcd1dde7eaf5c1e3fec01cce2b8 /notFinishedCode/tricode/insertData.php
parentMerge branch 'master' of lab.ks.uni-freiburg.de:lsfks/projekte/gsm-selftest (diff)
downloadgsm-selftest-b42ef6d7bc5b8974e0b88d96170be58a186b652b.tar.gz
gsm-selftest-b42ef6d7bc5b8974e0b88d96170be58a186b652b.tar.xz
gsm-selftest-b42ef6d7bc5b8974e0b88d96170be58a186b652b.zip
first working test website connected to the testing software!
Diffstat (limited to 'notFinishedCode/tricode/insertData.php')
-rw-r--r--notFinishedCode/tricode/insertData.php81
1 files changed, 81 insertions, 0 deletions
diff --git a/notFinishedCode/tricode/insertData.php b/notFinishedCode/tricode/insertData.php
new file mode 100644
index 0000000..fe77587
--- /dev/null
+++ b/notFinishedCode/tricode/insertData.php
@@ -0,0 +1,81 @@
+<?
+/*
+//Connection stuff
+//DB
+$dbhost = 'localhost';
+$dbuser = 'root';
+$dbpass = 'randompasswordSQL';
+
+
+$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
+
+$dbname = 'gsmselftesting';
+mysql_select_db($dbname);
+//End of connection stuff
+*/
+function getNewTaskNo()
+{
+ $sql = "SELECT MAX(taskNo) FROM TaskTable"; //the SQL command to find the max value in taskNo
+ $execute = mysql_query($sql); //execute the command
+ $result = mysql_result($execute,0);
+
+ if ($result == NULL)
+ {
+ // there is no single job in the table
+ return 1;
+ }
+ else
+ {
+ //increment the new taskNo
+ return $result + 1;
+ }
+}
+
+function insertTask($taskNo, $from, $to)
+{
+ $trans = "START TRANSACTION;";
+ $execute = mysql_query($trans);
+
+ if ($execute!=1)
+ {
+ return 3; //could not start transaction
+ }
+
+ $sql = "INSERT INTO `TaskTable` (`taskNo`, `from`, `to`) VALUES($taskNo, '$from', '$to')";
+ $execute = mysql_query($sql); //insert new task into the TaskTable
+
+ if ($execute == 1) //I added to the DB the task!
+ {
+ $sql = "SELECT @taskID := LAST_INSERT_ID()"; //find the last taskId
+ $execute = mysql_query($sql);
+ $taskId = mysql_result($execute,0); //I have the last taskId which I will use to insert it into TempTaskTable
+
+ $sql = "INSERT INTO `TempTaskTable` (`taskID`, `taskNo`, `from`, `to`) VALUES($taskId, $taskNo, '$from', '$to')";
+ $execute = mysql_query($sql); //insert new task into the TempTaskTable
+
+ if ($execute == 1)
+ {
+ $trans = "COMMIT;"; //command to end the transaction
+ $execute = mysql_query($trans);//finish the transaction
+
+ if ($execute == 1)
+ {
+ return 1; //task was successfuly added to both tables, TaskTable and TempTaskTable
+ }
+ else
+ {
+ return 0; //nothing was added to the tables
+ }
+ }
+ else
+ {
+ return 2; //the task is in the TaskTable but not in TempTaskTable
+ }
+ }
+ else
+ {
+ return 0; //nothing was added to the table, some error occured
+ }
+}
+ //include 'post.php';
+?>