Nayrb
Nayrb

Reputation: 1043

INSERT query is not letting me post data to database

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. 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 phpMyAdmin has only two field, id(autoincrement) and comment.

Upvotes: 1

Views: 701

Answers (1)

Ruel
Ruel

Reputation: 15780

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)

Upvotes: 2

Related Questions