Code: Select all
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="nobility"; // Mysql password
$db_name="test"; // Database name
$tbl_name="forum_topics"; // Table name -- LEAVE THIS AS IT IS
mysql_connect($host, "$username", "$password")or die("cannot connect");
mysql_select_db($db_name)or die("cannot select DB");
if (isset($_GET['type']) && $_GET['type'] == "setup") {
$sql = "CREATE TABLE `forum_topics` (
`id` int(4) NOT NULL auto_increment,
`topic` varchar(255) NOT NULL default '',
`detail` longtext NOT NULL,
`name` varchar(65) NOT NULL default '',
`email` varchar(65) NOT NULL default '',
`datetime` varchar(25) NOT NULL default '',
`view` int(4) NOT NULL default '0',
`reply` int(4) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;";
$sql2 = "CREATE TABLE `forum_replies` (
`thread_id` int(4) NOT NULL default '0',
`a_id` int(4) NOT NULL default '0',
`a_name` varchar(65) NOT NULL default '',
`a_email` varchar(65) NOT NULL default '',
`a_answer` longtext NOT NULL,
`a_datetime` varchar(25) NOT NULL default '',
KEY `a_id` (`a_id`)
) TYPE=MyISAM;";
mysql_query($sql);
mysql_query($sql2);
}elseif (isset($_GET['type']) && $_GET['type'] == "create") {
echo "<table width=\"400\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"1\" bgcolor=\"#CCCCCC\"><tr><form id=\"form1\" name=\"form1\" method=\"post\" action=\"".$PHP_SELF."?type=post\"><td><table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#FFFFFF\"><tr><td colspan=\"3\" bgcolor=\"#E6E6E6\"><strong>Create New Topic</strong> </td></tr><tr><td width=\"14%\"><strong>Topic</strong></td><td width=\"2%\">:</td><td width=\"84%\"><input name=\"topic\" type=\"text\" id=\"topic\" size=\"50\" /></td></tr><tr><td valign=\"top\"><strong>Detail</strong></td><td valign=\"top\">:</td><td><textarea name=\"detail\" cols=\"50\" rows=\"3\" id=\"detail\"></textarea></td></tr><tr><td><strong>Name</strong></td><td>:</td><td><input name=\"name\" type=\"text\" id=\"name\" size=\"50\" /></td></tr><tr><td><strong>Email</strong></td><td>:</td><td><input name=\"email\" type=\"text\" id=\"email\" size=\"50\" /></td></tr><tr><td> </td><td> </td><td><input type=\"submit\" name=\"Submit\" value=\"Submit\" /> <input type=\"reset\" name=\"Submit2\" value=\"Reset\" /></td></tr></table></td></form></tr></table>";
}elseif (isset($_GET['type']) && $_GET['type'] == "post") {
$topic=$_POST['topic'];
$detail=$_POST['detail'];
$name=$_POST['name'];
$email=$_POST['email'];
$datetime=date("d/m/y h:i:s"); //create date time
$sql="INSERT INTO $tbl_name(topic, detail, name, email, datetime)VALUES('$topic', '$detail', '$name', '$email', '$datetime')";
$result=mysql_query($sql);
if($result){
echo "Successful<BR>";
echo "<a href=\"".$PHP_SELF."\">View your topic</a>";
}else {
echo "Error Posting.";
}
}elseif (*some Code Here) {
*some Code Here
}
The Problem in the code above is that it doesn't create the rows and didn't write the datas in the database....
I am a newbie in php.. pls help me..and tell me what is wrong in the code...