latestEvent.php
<div id="news">
<h1>Latest Event</h1><p>
<span class="forum_locheader"></span><br />
<a href="index.php">Home</a>
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="fyp"; // Database name
$tbl_name="event"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name ORDER BY id ASC";
// OREDER BY id DESC is order result by descending
$result=mysql_query($sql);
?>
</p><table border="1" cellpadding="0" cellspacing="0" width="150%">
<br/>
<?php
while($rows=mysql_fetch_array($result)){ // Start looping table row
?>
<form>
<tr>
<?php echo $rows['topic']; ?><br/><?php echo $rows['detail']; ?><a href="delete_topic2.php"><img src="images/delete.jpg" border="0" /></a><br/>
<p class="comments align-right"> <a href="forum1.php">Read
more in forum section</a> </p> <a href="updateEvent.php">Update</a>
<br/>
<br/>
<br/>
</tr>
</form>
<?php
// Exit looping and close connection
}
mysql_close();
?>
<div class="newsitems"><p class="comments align-left">More news about latest event
in <a href="forum1.php"> FORUM</a> <a href="forum1.php"><img src="images/arrowhead.gif" width="100px" height="50px" border=""/></a></p>
<br/>
</div>
<div class="clear"></div>
<tr>
<td colspan="1" align="right" bgcolor="white"><a href="create_topic1.php"><strong>
Add a new Event</strong> </a></td>
</tr>
</table>
</div>
create_topic1.php
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Create New Topic</title>
<style type="text/css">
.style1 {
margin-bottom: 0px;
}
.style2 {
margin-left: 329px;
}
</style>
</head>
<body>
<table width="700" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="white">
<tr>
<form id="form1" name="form1" method="post" action="add_topic4.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td colspan="3" bgcolor="#E6E6E6"><strong>Add New Event</strong> </td>
</tr>
<tr>
<td style="width: 21%"><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" style="width: 11%"><strong>Detail</strong></td>
<td valign="top">:</td>
<td>
<textarea name="detail" id="detail" class="style1" style="width: 474px; height: 181px"></textarea></td>
</tr>
<tr>
<td style="width: 11%"><strong>Name</strong></td>
<td>:</td>
<td><input name="name" type="text" id="name" size="50" style="width: 357px" /></td>
</tr>
<!--<tr>
<td style="width: 11%"><strong>Email</strong></td>
<td>:</td>
<td><input name="email" type="text" id="email" size="50" style="width: 358px" /></td>
</tr>-->
<tr>
<td style="width: 11%"> </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>
<form>
<input type="button" value="Back" onclick="history.go(-1); return true;" style=" width: 118px" class="style2"/></form>
</body>
</html>
this is the code for the insert function: add_topic.php
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="fyp"; // Database name
$tbl_name="event"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Get value of id that sent from hidden field
$id=$_POST['id'];
// Find highest number.
$sql="SELECT MAX(id) AS Maxa_id FROM $tbl_name WHERE topic='$topic'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
// add + 1 to highestnumber and keep it in variable name "$Max_id".
if ($rows) {
$Max_id = $rows['Maxa_id']+1;
}
else {
$Max_id = 1;
}
// get values that sent from form
$topic=$_POST['topic'];
$detail=$_POST['detail'];
$name=$_POST['name'];
$sql2="INSERT INTO $tbl_name(id,topic,detail,name)VALUES('$Max_id', '$topic', '$detail', '$name')";
$result2=mysql_query($sql2);
if($result2){
echo "Successful<BR>";
echo "<a href='latestEvent.php".$id."'>View event</a>";
}
else {
echo "ERROR";
}
mysql_close();
?>
This is my code for delete function: delete_topic.php
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="fyp"; // Database name
$tbl_name="event"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("fyp")or die("cannot select DB");
//get data sent from form;
$id = $_GET['id'];
echo $id;
$delete1="DELETE FROM event WHERE id='$id'";
$result4=mysql_query($delete1);
if($result4)
{
echo "Successful<BR/>";
echo "<a href=latestEvent.php>View the page</a>";
}
else
{
echo "ERROR";
}
//}
mysql_close();
?>
<a href="latestEvent.php >View your event"</a>
my MySQL database query:
Table event
CREATE TABLE `event`
`id` int(5) NOT NULL auto_increment,
`topic` varchar(255) NOT NULL default '',
`detail` longtext NOT NULL,
`name` varchar(65) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;
Any help i would be really appreciate.Thanks

New Topic/Question
Reply




MultiQuote







|