Пример #1
0
function addSubject($uname, $title)
{
    global $connection;
    // not working check the function
    //    if(findSubjectAvailabilty($uname,$title)){
    //        echo "<p style=\"color:seashell;background:#f04848;padding:10px;font-                                          size:20px;font-family:Ubuntu\">Subject already available</p><br/>";
    //    }
    //calculating the positon
    $position = calcPosition(1);
    $datestamp = date('jS F Y');
    $query = "insert into subjects (title, authorname, datestamp, position, visible) values(";
    $query .= " '{$title}', '{$uname}', '{$datestamp}', {$position}, 1)";
    $result = mysqli_query($connection, $query);
    confirm_query($result);
}
Пример #2
0
    $userdata = getData($_SESSION["loggeduser"]);
    if ($userdata == null) {
        redirectTo("index.php");
    }
} else {
    redirectTo("index.php");
}
?>

<?php 
if (isset($_POST['save'])) {
    $title = mysqlPrep($_POST['title']);
    $content = mysqlPrep($_POST['content']);
    $stamp = date('jS F Y');
    $user = $_SESSION["loggeduser"];
    $position = calcPosition(2);
    $subjectid = findSubject(mysqlPrep($_POST['subjectname']));
    $query = "insert into posts (title,content,datestamp,authorname,position,visible,subjectid) values(";
    $query .= " '{$title}', '{$content}', '{$stamp}', '{$user}', {$position}, 1, {$subjectid})";
    //get the username from the session above in the case of author and also add stuff for selecting the subject from the subject list of that author
    $res = mysqli_query($connection, $query);
    if ($res) {
        echo "<p style=\"color:seashell;background:#f04848;padding:10px;font-size:20px;\">Saved</p>";
    } else {
        echo "<p style=\"color:seashell;background:#f04848;padding:10px;font-size:20px;\">Oops ! Something went wrong.</p>";
    }
}
if (isset($_POST['publish'])) {
    redirectTo("admin.php#posts");
}
// To update a particular post