function AddUniqueQuestion($paperName, $questionNum, $questionInfo, $questionType, $questionSelect, $questionScore)
{
    include_once '../DAL/questionDal.php';
    $paperID = GetPaperID($paperName);
    $result = FindQuestionByPaperID($paperID);
    foreach ($result as $single) {
        $questionID = $single[0];
        $qNumber = $single[2];
        if ($qNumber >= $questionNum) {
            $qNumber++;
            UpdateQuestionNum($questionID, $qNumber);
        }
    }
    InsertQuestion($paperID, $questionNum, $questionInfo, $questionType, $questionSelect, $questionScore);
    return 1;
}
示例#2
0
     <?php 
ini_set('short_open_tag', 'on');
require 'function/connect.php';
require 'function/dbfunction.php';
session_start();
if (isset($_SESSION['questionid'])) {
    $id = $_SESSION['questionid'];
}
// How to fetch from and insert into database
if (isset($_POST['savequestion'])) {
    // if the previous page was the Ask a Question page
    $name = mysqli_real_escape_string($conn, $_POST['name']);
    $email = mysqli_real_escape_string($conn, $_POST['email']);
    $topic = mysqli_real_escape_string($conn, $_POST['topic']);
    $content = mysqli_real_escape_string($conn, $_POST['content']);
    InsertQuestion($conn, $name, $email, $topic, $content);
    $id = SelectLastID($conn);
    $vote = GetVote($conn, $id);
    $datetime = GetDateTime($conn, $id);
} else {
    if (isset($_POST['editquestion'])) {
        // if the previous page was the Edit Question page
        $name = mysqli_real_escape_string($conn, $_POST['name']);
        $email = mysqli_real_escape_string($conn, $_POST['email']);
        $topic = mysqli_real_escape_string($conn, $_POST['topic']);
        $content = mysqli_real_escape_string($conn, $_POST['content']);
        EditQuestion($conn, $id, $name, $email, $topic, $content);
        $vote = GetVote($conn, $id);
        $datetime = GetDateTime($conn, $id);
    } else {
        if (isset($_POST['saveanswer'])) {
示例#3
0
    //insert course into db
    $result = pg_query($dbconnection, "INSERT INTO course VALUES ('{$coursecode}','made up quizname');");
    //give elf rights
    $result = pg_query($dbconnection, "INSERT INTO coursestaken VALUES ('{$coursecode}',3);");
    //clear all questions
    $result = pg_query($dbconnection, "DELETE FROM question WHERE quizname='{$name}';");
    //re add them all
    $result = pg_query($dbconnection, "INSERT INTO quiz (name, coursecode) VALUES ('{$name}', '{$coursecode}');");
    if (!$result) {
        return "fail";
    } else {
        return "success";
    }
}
if (isset($_POST['funcName'])) {
    switch ($_POST['funcName']) {
        case 'InsertQuestion':
            echo InsertQuestion($_POST['quizname'], $_POST['body'], $_POST['canswer'], $_POST['type'], $_POST['tolerance'], $_POST['imagename'], $_POST['panswerid'], $_POST['modelanswer']);
            break;
        case 'InsertQuiz':
            echo InsertQuiz($_POST['quizname'], $_POST['coursecode']);
            break;
    }
}
?>