newb help question: php mysql comment box?

Where may I host my php/mysql web site ?

Moderators: macek, egami, gesf

Post Reply
User avatar
L33R
New php-forum User
New php-forum User
Posts: 144
Joined: Fri Dec 30, 2011 4:27 am
Location: Liverpool

Re: newb help question: php mysql comment box?

Post by L33R » Wed Jan 18, 2012 9:06 am

They are notices telling you that they haven't been set anywhere. When you first run comment.php there is no such thing as $_POST['comment']. that will be initialized when you click submit on the form.

The variable $dname just isnt getting set anywhere. This needs to be inserted into the database with the comment.

change this

Code: Select all

<?php /*?>file name "comment.php"<?php */?>
<?php
require('connect.php');


$comment=$_POST['comment'];
$submit=$_POST['submit'];
if($submit)
{
    if($comment)
    {
    $query=mysql_query("INSERT INTO comment (id,comment) VALUES ('','$comment')");
    header("Location: success.php");
    }
    else
    {
        echo "ADD DATA";
    }
}
?>
<html>
<head><title></title></head>
<body>
<form action="comment.php" method="POST">
 </label><br /><br /><br />
<label>Comment:  </label><br /><textarea name="comment" cols="25" rows="7"></textarea><br /><br /><br />
<input type="submit" name="submit" value="Comment" /><br />

</form>
<hr width="1100px" size="5px" />
</body>
<?php
require('connect.php');
$query=mysql_query("SELECT * FROM comment ORDER BY id DESC");
while($rows=mysql_fetch_assoc($query))
{
     $id=$rows['id'];
     
     $dcomment=$rows['comment'];
     $linkdel="<a href=\"delete.php?id=" . $rows['id'] . "\">Delete User</a>";
     echo $dname . '<br />' . '<br />' . '<font color="red">Comments:</font>  ' . '<br />' . $dcomment . '&nbsp' . '&nbsp' .
      '&nbsp' . '&nbsp' .  $linkdel . '<br />' . '<br />' . 
     '<hr size="5px" width="500px" color="blue" />'  ;    
}
?>
</html>

(I have my id set to AUTO_INCREMENT so there is no need for it to be INSERTED)
you will have to check your settings in your database.

to something like this

Code: Select all

<?php
   require_once('connect.php');
	if (isset($_POST['comment'])) {
		$sql = "INSERT INTO comment (name,comment) VALUES ('{$_POST['name']}','{$_POST['comment']}');";
		mysql_query($sql) or die("error with insert " . mysql_error());
		
		header("Location: success.php");
		exit;
    }
		else
    {
        echo "No Comments set";
    }

?>
<html>
<head><title></title></head>
<body>
<form action="selfSubmit.php" method="POST">
 </label><br /><br /><br />
<label>Comment:  </label><br /><textarea name="comment" cols="25" rows="7"></textarea><br /><br /><br />
<label>Name:</label> <input type="text" name="name" size="30"/><br />
<input type="submit" name="submit" value="Comment" /><br />

</form>
<hr width="1100px" size="5px" />
</body>
<?php
equire('connect.php');
$query=mysql_query("SELECT * FROM comment ORDER BY id DESC");
while($rows=mysql_fetch_assoc($query))
{
     $id=$rows['id'];
     
     $dcomment=$rows['comment'];
	 $dname = $rows['name'];
     $linkdel="<a href=\"delete.php?id=" . $rows['id'] . "\">Delete User</a>";
     echo $dname . '<br />' . '<br />' . '<font color="red">Comments:</font>  ' . '<br />' . $dcomment . '&nbsp' . '&nbsp' .
      '&nbsp' . '&nbsp' .  $linkdel . '<br />' . '<br />' . 
     '<hr size="5px" width="500px" color="blue" />'  ;    
}
?>
</html>
You also need to be looking at Mysql_real_escape_string(); etc... for inputting into sql.

you may need to play around with it a bit.

skyhost92
New php-forum User
New php-forum User
Posts: 44
Joined: Wed Jan 25, 2017 2:50 am
Location: Pakistan
Contact:

Re: newb help question: php mysql comment box?

Post by skyhost92 » Thu Mar 16, 2017 12:17 am

We offer best web hosting in Pakistan. Sky Host is leading web hosting company which provides top web hosting services.We also offer dedicated servers, Pakistan based servers, shared hosting packages, VPS hosting, reseller hosting, WordPress, and Joomla hosting at reasonable prices.

skyhost92
New php-forum User
New php-forum User
Posts: 44
Joined: Wed Jan 25, 2017 2:50 am
Location: Pakistan
Contact:

Re: newb help question: php mysql comment box?

Post by skyhost92 » Thu Mar 16, 2017 12:59 am

Sky Host provides best web hosting services at lowest costs in all over Pakistan. We offer shared web hosting, VPS hosting, Corporate hosting, reseller hosting, dedicated servers, and Pakistan based servers at lowest costs. We provide 24/7 customer support via call and email.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest