PHP Series – Building A PHP MySQL Forum Tutorial Series Part 3.3 – Creating Topics




Follow me on Twitter @ http://twitter.com/tktutorials Check out my website @ http://www.timkipptutorials.com This is part three of this tutorial series. In part three …

Original source


36 responses to “PHP Series – Building A PHP MySQL Forum Tutorial Series Part 3.3 – Creating Topics”

  1. You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'now())' at line 6

  2. there is a little bug in the if-else logic in  create_topic_parse, as it takes input even if one of the field is empty. 
    it should've been

    if(($_POST['topic_title']!=="") && ($_POST['topic_content'] !== "")){
    …….all the codes……..
    }else{
    echo "u must fill both field"
    }

  3. I've run into a problem maybe someone can help me? 
    Its important to note that I am combining this with my own template.

    I have the create-topic-parse.php finished and correct.
    <?php 
    if(isset($_POST['submit'])) {
    if (($_POST['title'] == "") && ($_POST['content'] == "")) {
    echo "You did not fill in both fields. Please return to the previous page. ";
    exit();
    }
    else{

    $cid = $_POST['cid'];
    $title = $_POST['topic_title'];
    $content = $_POST['topic_content'];
    $creator = $_POST['uid'];
    $sql = "INSERT INTO topics (category_id, topic_title, topic_creator, topic_date, topic_reply_date) VALUES ('".$cid."', '".$title."', '".$creator."', now(), now())";
    $res = mysql_query($sql) or die(mysql_error());
    $new_topic_id = mysql_insert_id();
    $sql2 = "INSERT INTO posts (category_id, topic_id, post_creator, post_content, post_date) VALUES ('".$cid."'),('".$new_topic_id."'), ('".$creator."'), ('".$content."'), now())";
    $res2 = mysql_query($sql2) or die(mysql_error());
    $sql3 = "UPDATE categories1 SET last_post_date=now(), last_user_posted='".$creator."' WHERE id='".$cid."' LIMIT 1";
    $res3 = mysql_query($sql3) or die(mysql_error());
    if(($res) && ($res2) && ($res)) {
    header("Location: view_topic.php?cid=".$cid."$tid=".$new_topic_id);
    }
    else{
    echo "There was a problem. Try again.";
    }
    }
    }

    ?>

    I also have the form from the create-topic.php

    <form action="create-topic-parse.php" method="post">
    <p>Topic Title:<br>
    <input type="text" name"title" value="title">
    </p>
    <p>Topic Content:<br>
    <textarea type="text" name"content"></textarea>
    </p>
    <p><input type="hidden" name="cid" value="<?php echo $cid; ?>" ></p>
    <p><input type="submit" name="submit" value="Create"></p>
    </form>

    I've been debugging this for many hours now. It doesnt seem to be passing the post informatoin through to the create-topic-parse from the form. I just keep getting the error message… which means it is getting a post value from submit :/ in order to get into the conditional branch.

    Kind regards
    — DevonLively

  4. HeyIm creating a forum with php, javascript and mysql but i dispaly all data from the database on 1 page, I mean i never reload the webpage. If I want url links to all post on the forum how is that done? 🙁

  5. I've gotten a problem with
    Undefined variable: topics in C:xampphtdocsview_category.php on line 43 and line 43 looks like this $topics .= "<table width='100%' style='border-collapse: collapse;'>";

    and 46 $topic .= "<tr><td colspan='3'><hr /></td><tr>";

  6. This is my link: [create_topic_phrase is names as create_topic_create]

    MYWEBSITE/create_topic_create.php?topic_title=&topic_content=&cid=2&topic_submit=<a+href%3D%27create_topic.php%3Fcid%3D%272%27><p>%7C+Click+here+to+create+a+topic.<%2Fp><%2Fa>

  7. Hey! I get this error when creating the topic. " You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') VALUES ('2','11','1','test',now())' at line 1

  8. Notice: Undefined variable: email in C:xampphtdocsComplete_Source_Codepost_reply_parse.php on line 58

    Notice: Undefined variable: email in C:xampphtdocsComplete_Source_Codepost_reply_parse.php on line 58

  9. hello i got this error:
    Notice: Undefined variable: topics in C:xampphtdocsComplete_Source_Codeview_category.php on line 83

    Notice: Undefined variable: topic in C:xampphtdocsComplete_Source_Codeview_category.php on line 86,
    Notice: Undefined variable: userids in C:xampphtdocsComplete_Source_Codepost_reply_parse.php on line 39

  10. Sorry I was not able to reply quick enough. I'm glad you figured it out.

    Right now if you donate $6 or more to my PayPal account, admin(AT)timkipptutorials(DOT)com, I will send you a link to download the complete DVD series and code.

  11. I found out the Error.. Hahahah I am happy now.
    I forgot to add : post_creator after topic_id. I had 4 queries for 5 values.
    $sql = "INSERT INTO posts (category_id, topic_id, post_content, post_date) VALUES ('".$cid."','".$tid."','".$creator."','".$reply_content."', now())";

    Great Tutorial Tim.
    Where can i buy the DVD or souce code?

  12. When it goes to create_topic_parse.php I get this error:
    Notice: Undefined index: cid in D:wamp w.ww forumcreate_topic_parse.php on line 17
    I've checked over the code several times but I can't find a solution

  13. You could perform a query that would retrieve the username of the user based on the userID you pass into the query. Also, you can download the complete source code on my website in the Code Bank under the PHP/MySQL section.

  14. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id='' LIMIT 1' at line 1

    Any ideas?

  15. header("Location: view_topic.php?cid=".$cid."&ti­­d=".$new_topic_id.");
    you forgot the ending quotation marks. you also need to make sure you are giving values to $cid, $tid, and $new_topic_id as I stated in the forums.

  16. @jago125 Yeah when I made this tutorial series I was using a different server than what I normally use and it didn't throw the undefined variable error. I now make sure I check before running my scripts. Thanks for the feedback.

Leave a Reply