Code: Select all
<?php
$result3 = mysql_query("SELECT * FROM post_data ORDER BY id");
$content = $row['content'];
$dates = date("l, F d, Y " );
$id = $_GET['id'];
$result4 = mysql_query("SELECT id FROM user_comments WHERE id = '$id'");
$result3 = mysql_query("SELECT id FROM post_data WHERE id = '$id'");
$num_rows = mysql_num_rows($result3);
$num_rows1 = mysql_num_rows($result4);
$result = mysql_query("SELECT * FROM post_data WHERE id = '$id'");
$result2 = mysql_query("SELECT * FROM user_comments WHERE id = '$id' ORDER BY date_comment");
$row = mysql_fetch_array($result);
if (mysql_num_rows($result3)==0){
header('location:viewquestions.php');
}else{
// Your normal code
echo "<table class='backbtn' border='0'>";
echo "<tr>";
echo "<td class='backbtn'>" . "<a class='backbtn' href='viewquestions.php'>" . "Back" . "</a>" . "</td>";
echo "</tr>";
echo "</table>";
echo "<table class='title' border='0'>";
echo "<tr>";
echo "<td class='title'>" . $row['text'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "</table>";
echo "<table border = '0' class='post'>";
if (isset($_POST['Submit'])){
if (empty($_POST['name']) || empty($_POST['post']))
{
$Text = "Please fill in all the fields.";
echo "<script type='text/javascript'>alert('{$Text}');</script>";
}
else
{
mysql_query("INSERT INTO user_comments (id,comment,date_comment,name)VALUES ('$id','$_POST[post]','$dates','$_POST[name]')");
header('location:view_place1.php?id=' . $id);
}
}
}
?>
<?php
if($num_rows1 > 3){
echo "This page has reached the maximum posts:D";
echo "<table class='comment' border='0'>";
while($row2 = mysql_fetch_array($result2))
{
echo "<tr class='user_comment'>";
echo "<td class='user'>" . "<div class='commentuser'>" . $row2['name'] . "</div>" . "<div class='commentdate'>" . $row2['date_comment'] . "</div>" . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td class='usercomment'>" . $row2['comment'] . "</td>";
"</tr>";
}
echo "</table>";
}
else
{
if($num_rows1 < 1){
echo "
<table class='commentbox' border='0'>
<tr>
<td>
<form class='comment' method='post' action=''>
Name<p align='center'><textarea name='name' tabindex='4' title='name' id='comment' class='forminput' rows='3' cols='30' name='comment' ></textarea></p>
Comments<p align='center'><textarea name='post' tabindex='4' id='comment' class='forminput' rows='3' cols='30' name='comment'></textarea></p>
<p align='center'><input type='submit' value='Submit' class='submitbtn' name='Submit' onclick='this.disabled=true' id='Submit' /></p>
</form>
</td>
</tr>
</table>";
}
else{
echo "<table class='comment' border='0'>";
while($row2 = mysql_fetch_array($result2))
{
echo "<tr class='user_comment'>";
echo "<td class='user'>" . "<div class='commentuser'>" . $row2['name'] . "</div>" . "<div class='commentdate'>" . $row2['date_comment'] . "</div>" . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td class='usercomment'>" . $row2['comment'] . "</td>";
"</tr>";
}
echo "</table>";
echo "
<table class='commentbox' border='0'>
<tr>
<td>
<form class='comment' method='post' action=''>
Name<p align='center'><textarea name='name' tabindex='4' title='name' id='comment' class='forminput' rows='3' cols='30' name='comment' ></textarea></p>
Comments<p align='center'><textarea name='post' tabindex='4' id='comment' class='forminput' rows='3' cols='30' name='comment'></textarea></p>
<p align='center'><input type='submit' value='Submit' class='submitbtn' name='Submit' onclick='this.disabled=true' id='Submit' /></p>
</form>
</td>
</tr>
</table>";
}
}
?>it can only work inside html and outside php, so can anyone please tell me where did i do wrong?