Пример #1
0
 public static function create_table($name)
 {
     $query_string = "CREATE TABLE IF NOT EXISTS " . $name . "_users " . "(\n\t\t\t\t\t\t\t  `first_name` varchar(30) NOT NULL,\n\t\t\t\t\t\t\t  `last_name` varchar(30) NOT NULL,\n\t\t\t\t\t\t\t  `email` varchar(30) NOT NULL,\n\t\t\t\t\t\t\t  `phone_number` varchar(13) NOT NULL,\n\t\t\t\t\t\t\t  `score` int(11) NOT NULL DEFAULT '0',\n\t\t\t\t\t\t\t  `questions_attempted` int(11) NOT NULL DEFAULT '0',\n\t\t\t\t\t\t\t  `correct_ans` int(11) NOT NULL DEFAULT '0',\n\t\t\t\t\t\t\t  `wrong_ans` int(11) NOT NULL DEFAULT '0',\n\t\t\t\t\t\t\t  PRIMARY KEY (`email`),\n\t\t\t\t\t\t\t  UNIQUE KEY `phone_number` (`phone_number`)\n\t\t\t\t\t\t\t)";
     $db = new DB_CONNECT();
     $result = $db->query_database($query_string);
     return $result;
 }
Пример #2
0
 public static function create_table($name)
 {
     $query_string = "CREATE TABLE IF NOT EXISTS " . $name . "_questions" . "(\n\t\t\t\t\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t\t\t  `question` text NOT NULL,\n\t\t\t\t\t\t\t  `option1` text NOT NULL,\n\t\t\t\t\t\t\t  `option2` text NOT NULL,\n\t\t\t\t\t\t\t  `option3` text NOT NULL,\n\t\t\t\t\t\t\t  `option4` text NOT NULL,\n\t\t\t\t\t\t\t  `correct_ans` text NOT NULL,\n\t\t\t\t\t\t\t  `marks` int(11) NOT NULL,\n\t\t\t\t\t\t\t  `negative_marks` int(11) NOT NULL,\n\t\t\t\t\t\t\t  PRIMARY KEY (`id`)\n\t\t\t\t\t\t\t)";
     $db = new DB_CONNECT();
     $result = $db->query_database($query_string);
     return $result;
 }
Пример #3
0
<?php

require_once "../includes/db_connect.php";
require_once "../includes/functions.php";
require_once "../includes/session.php";
confirm_logged_in();
if (!is_null($_GET['question_id'])) {
    $test_name = urldecode($_GET['test_name']);
    $question_id = $_GET["question_id"];
    $db = new DB_CONNECT();
    $username = get_username();
    //$test_name = $db->mysql_prep($_POST["test_name"]);
    $table_name = $test_name . "_questions";
    $query = "DELETE FROM " . $table_name . " WHERE id='{$question_id}'";
    $result = $db->query_database($query);
    if (is_null($result)) {
        // query failed
        echo "query failed";
    } else {
        redirect_to('question_list.php?test_name={$test_name}');
    }
}
Пример #4
0
<?php

require_once '../includes/db_connect.php';
require_once '../includes/functions.php';
require_once '../includes/session.php';
confirm_logged_in();
$db = new DB_CONNECT();
// get username from the session
$username = get_username();
//select all test created by him from test table
if (isset($_GET["message"])) {
    $message = "The Test has been deleted.";
}
$query = "SELECT test_name,start_time,end_time,event_date,duration FROM test WHERE username='******'";
$admin_tests = $db->query_database($query);
if ($db->number_of_rows($admin_tests) > 0) {
    $i = 1;
    while ($row = $db->fetch_array($admin_tests)) {
        $table_data = array();
        $table_data_array[$i] = array();
        $table_data["test_name"] = $row["test_name"];
        $table_data["start_time"] = $row["start_time"];
        $table_data["end_time"] = $row["end_time"];
        $table_data["event_date"] = $row["event_date"];
        $table_data["duration"] = $row["duration"];
        $table_data_array[$i] = $table_data;
        $i++;
    }
    $no_of_rows = $i - 1;
    $table_data_array["number_of_rows"] = $no_of_rows;
    $table_html = make_test_information_table();
Пример #5
0
            if (is_null($result)) {
                // query failed
                echo "query failed";
            } else {
                redirect_to("question_list.php?test_name=" . get_test_name());
            }
        } else {
            echo "empty fields";
        }
    } else {
        echo "Someting was not set";
    }
} else {
    $db = new DB_CONNECT();
    $query = "SELECT * FROM test WHERE test_name='" . get_test_name() . "' AND username='******' ";
    $details = $db->query_database($query);
    if ($db->number_of_rows($details) > 0) {
        $i = 1;
        $row = $db->fetch_array($details);
        $table_data = array();
        $table_data["test_name"] = $row["test_name"];
        $table_data["start_time"] = $row["start_time"];
        $table_data["end_time"] = $row["end_time"];
        $table_data["event_date"] = $row["event_date"];
        $table_data["duration"] = $row["duration"];
    }
}
?>

<!DOCTYPE html>
<html>
Пример #6
0
<?php

require_once '../includes/db_connect.php';
require_once '../includes/functions.php';
require_once '../includes/session.php';
confirm_logged_in();
$db = new DB_CONNECT();
// get username from the session
$username = get_username();
$test_name = urldecode($_GET['test_name']);
//select all test created by him from test table
$query = "SELECT * FROM " . $test_name . "_users";
$users_table = $db->query_database($query);
if ($db->number_of_rows($users_table) > 0) {
    $i = 1;
    while ($row = $db->fetch_array($users_table)) {
        $table_data = array();
        $table_data_array[$i] = array();
        $table_data["first_name"] = $row["first_name"];
        $table_data["last_name"] = $row["last_name"];
        $table_data["email"] = $row["email"];
        $table_data["phone_number"] = $row["phone_number"];
        $table_data["score"] = $row["score"];
        $table_data["questions_attempted"] = $row["questions_attempted"];
        $table_data["correct_ans"] = $row["correct_ans"];
        $table_data["wrong_ans"] = $row["wrong_ans"];
        $table_data_array[$i] = $table_data;
        $i++;
    }
    $no_of_rows = $i - 1;
    $table_data_array["number_of_rows"] = $no_of_rows;
Пример #7
0
}
if (isset($_POST["submit"])) {
    $db = new DB_CONNECT();
    $keys = array("question", "option1", "option2", "option3", "option4", "radio", "marks", "negative_marks");
    if (!array_diff($keys, array_keys($_POST)) && check_is_set($_POST)) {
        $question = $db->mysql_prep($_POST["question"]);
        $option1 = $db->mysql_prep($_POST["option1"]);
        $option2 = $db->mysql_prep($_POST["option2"]);
        $option3 = $db->mysql_prep($_POST["option3"]);
        $option4 = $db->mysql_prep($_POST["option4"]);
        $correct_ans = $db->mysql_prep($_POST["radio"]);
        $marks = $db->mysql_prep($_POST["marks"]);
        $negative_marks = $db->mysql_prep($_POST["negative_marks"]);
        $table_name = get_test_name() . "_questions";
        $query = "Insert into " . $table_name . " (`question`, `option1`, `option2`, `option3`, `option4`, `correct_ans`, `marks`, `negative_marks`) \n       VALUES('{$question}','{$option1}','{$option2}', '{$option3}', '{$option4}', '{$correct_ans}', '{$marks}', '{$negative_marks}')";
        if (!is_null($db->query_database($query))) {
            redirect_to("add_question.php?message=true");
        } else {
            echo "Question cannot be added";
        }
    } else {
        $message = "Someting was not set";
    }
}
?>

<!DOCTYPE html>
<html>
   <head>
      <title>Add Question</title>
         <?php 
Пример #8
0
<?php

require_once "../includes/db_connect.php";
require_once "../includes/functions.php";
require_once "../includes/session.php";
confirm_logged_in();
if (!is_null($_GET['test_name'])) {
    $test_name = urldecode($_GET['test_name']);
    $db = new DB_CONNECT();
    $username = get_username();
    //$test_name = $db->mysql_prep($_POST["test_name"]);
    $query = "DELETE FROM test WHERE username='******' AND test_name='{$test_name}'";
    $result = $db->query_database($query);
    if (is_null($result)) {
        // query failed
        echo "query failed";
    } else {
        $user_table = $test_name . "_users";
        $questions_table = $test_name . "_questions";
        $query = "DROP TABLE {$user_table} ";
        $result = $db->query_database($query);
        $query2 = "DROP TABLE {$questions_table} ";
        $result2 = $db->query_database($query2);
        var_dump($query2);
        if (!is_null($result) && !is_null($result2)) {
            redirect_to('view_test.php?message=true');
        }
    }
}