4

I recently created a PHP/MySQL comment system, and it was working until a few hours ago (no changes at all in the code). When I tell the submit form code to echo the query, it shows that the area for commenttext and date is missing. I don't see why. Here's my code:

mysql_connect("localhost","commentUser","password");
mysql_select_db("comments");
$name = mysql_real_escape_string($_POST['name']);
$postID = mysql_real_escape_string($_POST['postId']);
if(!is_numeric($postID))
 exit();
$email = mysql_real_escape_string($_POST['email']);
$comment = strip_tags(mysql_real_escape_string($_POST['comment']), '');
$date = mysql_real_escape_string($_POST['date']);
if($email == '' || $comment = '' || $date = '')
 exit();
$query = "INSERT INTO comments (PostID,Name,Email,Text,Date) VALUES($postID, '$name', '$email', '$comment', '$date')";
mysql_query($query) or die(mysql_error());
mysql_close();
 echo "
 
 window.location = \"snippet.php?id=$postID\";
 
 ";
asked Sep 10, 2011 at 20:02
3
  • 1
    You should post the HTML code for the form Commented Sep 10, 2011 at 20:04
  • 1
    can you post the code of the html form? Commented Sep 10, 2011 at 20:05
  • Are the single equal signs typos in the post or are they in the actual code? if($email == '' || $comment = '' || $date = '') should all be double equals. Commented Sep 10, 2011 at 20:10

2 Answers 2

4

You are assigning the empty string to $comment and $date with =

if($email == '' || $comment = '' || $date = '')
 exit();
// Should use `==` for all three:
if($email == '' || $comment == '' || $date == '')
 exit();
answered Sep 10, 2011 at 20:17
Sign up to request clarification or add additional context in comments.

Comments

0

You are trying to compare $comment and $date with invalid character please replace this line: if($email == '' || $comment = '' || $date = '') with if($email == '' || $comment = '' || $date == '')

Sébastien Renauld
19.8k2 gold badges50 silver badges69 bronze badges
answered May 28, 2019 at 10:40

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.