Insert message from comment system into database – Learn PHP backend programming. Today we will insert comments into our database directly from the …



  1. I tried adding and removing the second root in and the error is still there saying Parse error: syntax error, unexpected 'root'(T_STRING)

  2. I accidentally put the comma inside the apostrophe. You won't get any errors on screen if you make this mistake and no data will be put in the table.

    $sql = "INSERT INTO comments (uid, date, message) VALUES ('$uid,' '$date', '$message')";
    Changed to:
    $sql = "INSERT INTO comments (uid, date, message) VALUES ('$uid', '$date', '$message')";

  3. if anyone run into the problem that your database doesnt receive your text, try to use $con instead of $conn, it somehow worked for me

  4. Thanks for the tutorial, i would like your help! when you have several posts that can be commented on , how do you get the ID of each post such that every comment has an id of the corresponding post where it was made. How do i pass that ID so that i can insert it into the database when am inserting the comment. thanks u.

  5. Hi . I hav all d backend codes for d comment section but in my browser it displays dat it cant find my database.which I have correctly done.

  6. i was trying for hours to see why on page refresh page comments appears again
    header("Location: ".$_SERVER['REQUEST_URI']);
    i used this inside isset for button submit and all fine

  7. <?php
    function setComments($conn) {
    if (isset($_POST['commentSubmit'])) {
    include_once '';
    $message=$_POST ['message'];

    $sql= "INSERT INTO comments (uid, date, message)
    VALUES ('$uid', '$date', '$message')";
    $result= mysqli_query($conn, $sql);

    this code keeps giving me this errors:
    Notice: Undefined index: uid in on line 5

    Notice: Undefined index: dat in on line 6

    Can you tell me why?

  8. I tried sending the message to the database but the message did not go to the database can i have some help please

  9. Hey mmtuts, I just have a simple question that I was hoping you could answer. What do you mean by you mixed up Procedural PHP with OOP PHP? What's the difference?

    If you can't provide a brief answer, then I'm happy to look up the answer in my own time, but if you could that would be great.

  10. HELP!

    "Connection failed: Can't connect to MySQL server on 'localhost' (10061)"

    I get this message after connecting to database.
    How do i go about solving it?

  11. <?php

    <link rel="stylesheet" type="text/css" href="commentstyle.css">
    echo "<form method='POST' action=''>
    <input type='hidden' name='uid' value='Anonymous'>
    <input type='hidden' name='date' value='".date('Y-m-d H:i:s')."'>
    <textarea name='message' ></textarea><br><br>
    <button name='commentSubmit' type='submit'>Comment</button>
    echo' not connected to server' ;
    echo'database not selected';
    $uid =$_POST['uid'];
    $date = $_POST['date'];
    $message = $_POST['message'];
    $sql = "INSERT INTO comments (uid,date,message) VALUES('$uid','$date','$message')";
    echo 'not inserted';
    echo 'comment inserted';
    This should help you.😎✌️

  12. guys this will help you 🙂


    function setComments($conn){

    $uid = mysqli_real_escape_string($conn, $_POST['uid']);
    $date = mysqli_real_escape_string($conn, $_POST['date']);
    $message = mysqli_real_escape_string($conn, $_POST['message']);

    $sql= "INSERT INTO comments(uid, date ,message) VALUES ('$uid', '$date', '$message');";



  13. Hey there,
    I am a fan of your tutorials!! But do you mind doing a class on how to build your own shopping cart, I have seen many tutorials but they don't seem to explain the codes as well as you could!! Much appreciated

  14. i have form which is under echo like this,

    Code :


    echo "<form method='POST' action=' ".setComments." ' >

    it giving error undefined index 'f'.

    </form> ";


    what is issue?

  15. Hi, very beautiful and useful video!
    I'm using a mac with AMPPS instead of xamp.
    When I write the code $conn= mysqli_connect('localhost', 'root', '', 'commentsection'); it doesn't work.
    I have tried $conn= mysqli_connect('localhost', 'root', 'root', 'commentsection') but it doesn't work as well.
    Do you know what I can do?

  16. OK I have got it the reason why most peoples data is not being inserted is because of the date we created. I tried it severally yet it doesn't seem to be correct so I deleted the date row from database and also deleted it from my code and very other thing worked perfectly.
    I will post how to insert a date after working on other stuffs..

  17. Hello please no information from my message field gets inserted into the database table. Please what should I do?

Leave A Reply

Please enter your comment!
Please enter your name here