views:

44

answers:

2

I'm trying to implement a comment.php script that takes the data from a html textfield and save it to a database in phpmyadmin. I implemented registration.php, which is longer and it inserts new users flawlessly. Now the comment.php, which is simpler is not adding anything to a comments table.

Here's the code for comment.php:

<?php 

 session_start();
 require('connect.php');
 $id = $_SESSION['id'];
 $comment = $_POST['comment'];
 $sql = "INSERT INTO `comp595ose`.`comments` 
           (`id`, `comment`) 
         VALUES 
           (NULL, \'This is not working\');";

 $add_comment = mysql_query($sql);

 echo $comment." ";
 echo $id;
?>

the 'comments' table in myphpadmin has only two field, id(autoincrement) and comment.

+2  A: 

You don't need to escape the single quotes.

$sql = "INSERT INTO `comp595ose`.`comments` (`id`, `comment`) VALUES (NULL, 'This is not working');";

Try that.. (untested)

Ruel
Thank you. Now it is working.
Bryan Harrington
A: 

Well just looking at the code... why would you insert NULL into an id column ??

D0cNet
Because it's an auto-increment field
Ruel
I know but $sql = "INSERT INTO `comp595ose`.`comments` ( `comment`) VALUES ( 'This is not working');";looks and works better
D0cNet