1

So I have a comment post thingy for my blog I've made, but it doesn't seem to be inserting the data. Here's the form:

<form action='' method='post' name='postComment'>
<label for='name'>Name:</label><br/><input type='text' id='name' name='name''/><br/>
<label for='comment'>Comment:</label><br/><input type='text' id='comment' name='comment' />
<br/><input type='submit' value='Post' name='postComment'/></form></div>

The form is processed on the same page in the top part of the page. I use the same way of inserting the data as the blog posts themselves so I know it works. I've also tested the SQL by using phpMyAdmin (obviously removing placeholders)

if(!empty($_POST['postComment']))
{
    $date = date("d/m/y g:i:A");
    $name = clean(mysqli_real_escape_string($db, $_POST['name']));
    $comment = clean(mysqli_real_escape_string($db, $_POST['comment']));
    if ($stmt = $db->prepare("INSERT INTO `comments` (`name`, `comment`, `entry`, `date`) values (?, ?, ?, ?)")) {
        $stmt->bind_param('ssis', $name, $comment, $_GET['id'], $date);
        $stmt->execute();
        $stmt->close();
    }
}

Any help would be appreciated, been scratching my head over this one for a day now.

Austen
  • 275
  • 1
  • 4
  • 16

3 Answers3

1

The data may need to be cleaned as well, in order to be entered with quotes around it. If you look at your query, you may see the date not being entered like a string, which it should be.

Bradley
  • 1,955
  • 1
  • 20
  • 28
  • 1
    Also, `$_GET['id']` is bound as an integer, while it's actually a string containing an integer. Unsure how that'd work. As a last thing too, bound strings don't need to be `mysqli_real_escape_string`'d before binding. – Joachim Isaksson Jul 25 '13 at 18:43
  • Just changed it to string – Austen Jul 25 '13 at 18:58
0

Solved it, thanks for everyone's help. For some reason phpMyAdmin did not set ID as auto-increment even though I set it when I made the table. A simple sql query solved it.

ALTER TABLE comments MODIFY id int NOT NULL AUTO_INCREMENT;
Austen
  • 275
  • 1
  • 4
  • 16
-1

Your form action='' is blank, so it's not going anywhere.

Kenzo
  • 3,117
  • 3
  • 14
  • 15