another hard 30mins work on tildechan. i got it setup where the actual thread is now inserted into the database, but not the post (threads and posts are seperate). there are still lots of todos to finish
This commit is contained in:
parent
baad016a84
commit
433ed2c621
17
post.php
17
post.php
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
$path = $_SERVER['DOCUMENT_ROOT'];
|
||||
require_once($path . '/core/database.php');
|
||||
|
||||
//function for image validation
|
||||
|
@ -7,6 +8,19 @@ function validate_iamge() {
|
|||
|
||||
// function to handle the creation of a new thread
|
||||
function new_thread(string $board_code, string $title, string $username) {
|
||||
|
||||
$conn = get_database_conn();
|
||||
$insert_thread_sql = "INSERT INTO thread (title, user_id, board, posted)
|
||||
VALUES (?, (SELECT id FROM user WHERE username = ?), ?, NOW())";
|
||||
$stmt = mysqli_prepare($conn, $insert_thread_sql);
|
||||
mysqli_stmt_bind_param($stmt, "sss", $title, $username, $board_code);
|
||||
mysqli_stmt_execute($stmt);
|
||||
|
||||
if (mysqli_stmt_affected_rows($stmt) != 1) {
|
||||
//todo: handle error
|
||||
}
|
||||
|
||||
//todo: return actual thread id
|
||||
}
|
||||
|
||||
// function to handle the creation of a new post
|
||||
|
@ -23,6 +37,7 @@ if ($_POST['type'] == 'new_thread') {
|
|||
// get the variables from the post request
|
||||
$title = $_POST['title'] or die('invalid request!');
|
||||
$upload = $_POST['upload'] or die('invalid request!');
|
||||
$board_code = $_POST['board_code'] or die('invalid request!');
|
||||
$message = $_POST['message'] ?? '';
|
||||
|
||||
// get the posters username
|
||||
|
@ -35,6 +50,8 @@ if ($_POST['type'] == 'new_thread') {
|
|||
|
||||
//todo: validate the image and move it into the filesystem
|
||||
|
||||
$thread_id = new_thread($board_code, $title, $username);
|
||||
|
||||
} elseif ($_POST['type'] == 'thread_reply') {
|
||||
} else {
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue