diff options
author | cflip <36554078+cflip@users.noreply.github.com> | 2021-01-24 13:21:18 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-24 13:21:18 -0700 |
commit | b08ca01d49b3683b62d2d9f2f6fefc1a73da71a0 (patch) | |
tree | 19cc321932c32fa79b8a28df3941bdbb4d68af46 | |
parent | 2d39a708bdd88dc1601badbc2f58843b757996e9 (diff) | |
parent | f78ad3e81c2bf8dca6b491ee8f09b99d40903d77 (diff) |
Merge pull request #3 from cflip/bugfix
A couple of bug fixes
-rw-r--r-- | create_thread.php | 29 | ||||
-rw-r--r-- | register.php | 4 |
2 files changed, 20 insertions, 13 deletions
diff --git a/create_thread.php b/create_thread.php index 3f15f63..51bfe10 100644 --- a/create_thread.php +++ b/create_thread.php @@ -39,7 +39,6 @@ if (!isset($_SESSION['signed_in'])) { <textarea name="post_content"></textarea><br> <input type="submit" name="submit"> </form> -</section> <?php include_once 'includes/db_inc.php'; @@ -66,8 +65,9 @@ function create_post($dbc, $post_content, $post_thread, $post_author) { } mysqli_stmt_bind_param($stmt, "sii", $post_content, $post_thread, $post_author); - mysqli_stmt_execute($stmt); + $result = mysqli_stmt_execute($stmt); mysqli_stmt_close($stmt); + return $result; } function validate($data) { @@ -78,22 +78,29 @@ function validate($data) { } if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $post_result = NULL; $post_content = validate($_POST['post_content']); $thread_subject = validate($_POST['thread_subject']); $thread_cat = validate($_POST['thread_cat']); $user_id = validate($_SESSION['user_id']); - create_thread($dbc, $thread_subject, $thread_cat, $user_id); - $thread_id = mysqli_insert_id($dbc); - create_post($dbc, $post_content, $thread_id, $user_id); - - if (!$post_result) { - echo 'An error occurred creating your post: ' . mysqli_error($dbc); + // Disallow empty thread subjects + if (empty($thread_subject) or !$thread_subject) { + echo '<br>Thread subject cannot be empty.'; + } else { + create_thread($dbc, $thread_subject, $thread_cat, $user_id); + $thread_id = mysqli_insert_id($dbc); + $post_result = create_post($dbc, $post_content, $thread_id, $user_id); + if (!$post_result) { + echo 'An error occurred creating your post: ' . mysqli_error($dbc); + } else { + header("Location: thread.php?id=" . $thread_id); + } } - - header("Location: thread.php?id=" . $thread_id); } ?> -<?php include_once 'footer.php';?>
\ No newline at end of file +</section> + +<?php include_once 'footer.php';?> diff --git a/register.php b/register.php index a318170..efa4486 100644 --- a/register.php +++ b/register.php @@ -68,7 +68,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { $user_pass = $_POST['user_pass']; $pass_check = $_POST['user_pass_check']; - if (preg_match("/^[a-zA-Z0-9\W]*$/", $user_name) === false) { + if (preg_match("/^[a-zA-Z0-9\W]*$/", $user_pass) === false) { $errors[] = "Password contains invalid characters!"; } @@ -104,4 +104,4 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { </section> -<?php include_once 'footer.php';?>
\ No newline at end of file +<?php include_once 'footer.php';?> |