i found the code below (i also uploaded the files in the attached "php_mysql_help.zip") . I altered it a little , but even before i edited it i got these error messages :
"Notice: Undefined index: comment in C:\xampp\htdocs\0_test_delete\comment.php on line 5
Notice: Undefined index: submit in C:\xampp\htdocs\0_test_delete\comment.php on line 6
Notice: Undefined variable: dname in C:\xampp\htdocs\0_test_delete\comment.php on line 40" .
I'm still in the infancy stage of .php & mysql , if you have some suggestion please respond to me as if i am a complete imbecile & don't know anything. How do I fix it ?
- 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 . ' ' . ' ' .
' ' . ' ' . $linkdel . '<br />' . '<br />' .
'<hr size="5px" width="500px" color="blue" />' ;
}
?>
</html>
- Code: Select all
<?php /*?>file name "connect.php"<?php */?>
<?php
$connect=mysql_connect("localhost","root","") or die('mysql_error()');
$database=mysql_select_db("comment") or die('mysql_error()');
?>
- Code: Select all
<?php /*?>file name "delete.php"<?php */?>
<?php
require('connect.php');
$deleteid=$_GET['id'];
mysql_query("DELETE FROM comment WHERE id='$deleteid'");
header("location: success.php");
?>
- Code: Select all
<?php /*?>file name "success.php"<?php */?>
<?php
header("Location: comment.php");
?>
- Code: Select all
--
-- Host: localhost
-- Generation Time: May 07, 2011 at 03:27 PM
-- Server version: 5.1.53
-- PHP Version: 5.3.4
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `comment`
--
-- --------------------------------------------------------
--
-- Table structure for table `comment`
--
CREATE TABLE IF NOT EXISTS `comment` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`comment` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
--
-- Dumping data for table `comment`
--
INSERT INTO `comment` (`id`, `name`, `comment`) VALUES
THANKS FOR YOUR TIME !

