index.php
Code: Select all
<?php
$host = "localhost";
$user = "root";
$pass = "";
$db = "ask";
$con = mysql_connect($host,$user,$pass);
mysql_select_db($db,$con);
//echo "<a href='create_topic.php'>New topic</a>";
echo "<table border='0' width='100%'>
<tr><td>#</td><td>forum</td><td>topics</td><td>Posts</td><td>last post by</td></tr>";
$sql = mysql_query("SELECT * FROM category ORDER BY cat_id ");
while($row = mysql_fetch_array($sql)) {
$replies = mysql_num_rows(mysql_query("SELECT * FROM replies WHERE topic_id='".$row['id']."'"));
echo "<tr><td>".$row['cat_id']."</td><td><a href='topic.php?id=".$row['cat_id']."'>".htmlentities($row['category_topic'])."</a></td><td>".$replies."</td><td>".date("j/n - y",$row['created'])."</td></tr>";
}
echo "</table>";
mysql_close($con);
?>
the above is the index .php
Code: Select all
<?
$id=$_GET['id'];
echo'<table>';
echo"<form action='add_topic.php' method='post'>
<tr><td>Name</td><td>:</td><td><input type='text' id='name' name='name' /></td></tr>
<tr><td>Email</td><td>:</td><td><input type='text' id='mail' name='mail' /></td></tr>
<tr><td>Title</td><td>:</td><td><input type='text' id='title' name='title' /></td></tr>
<tr><td valign='top'>Post</td><td valign='top'>:</td><td><textarea id='post' name='post' rows='7'></textarea></td></tr>
<tr><td> </td><td> </td><td><input type='submit' value='Post Topic' /> <input type='reset' value='Reset Fields' /></td></tr>
<input type='hidden' id='cat_id' name='cat_id' value=\".$id.\" />
</form>";
echo'</table>';
?>
and the above is the file create.php from which i am sendind the data to the script add_topic.php
add_topic.php
Code: Select all
<?php
if (!empty($_POST)) {
$host = "localhost";
$user = "root";
$pass = "";
$db = "ask";
$id=$_POST['cat_id'];
$con = mysql_connect($host,$user,$pass);
mysql_select_db($db,$con);
if (mysql_query("INSERT INTO topics (title,post,author,mail,date,cat_id) VALUES ('".$_POST['title']."','".$_POST['post']."','".$_POST['name']."','".$_POST['mail']."','".time()."','".$_POST['cat_id']."')")) {
header("location:topic.php?id=$id");
} else {
echo "Error!";
}
mysql_close($con);
}
?>
so the problem i s in the above script
and below is the file to which i wana redirect from add_topic.php
Code: Select all
<?php
if (isset($_GET['id'])){
$host = "localhost";
$user = "root";
$pass = "";
$db = "ask";
$con = mysql_connect($host,$user,$pass);
mysql_select_db($db,$con);
$id = $_GET['id'];
echo "<a href=\"create_topic.php?id=$id\">New topic</a>";
echo "<table border='0' width='100%'>";
$sql = mysql_query("SELECT * FROM topics WHERE cat_id='".$id."'");
while($row = mysql_fetch_array($sql)) {
echo "<tr><td>".htmlentities($row['title'])."</td></tr>
<tr><td>".str_replace("\n","<br />",htmlentities($row['post']))."</td></tr>
<tr><td><a href='mailto:".$row['mail']."'>".htmlentities($row['author'])."</a></td></tr>
<tr><td>".date("j/n - y",$row['date'])."</td></tr>";
}
echo "</table>";
mysql_close($con);
} else {
echo "invalid usage!";
}
?>
...now help