It is destroyed (as usual) when I click the submit button.
Insert query needs "$aut_id" value after the clicking of submit button.
How can I achieve this?
Following is my code
Code: Select all
<?php
mysql_connect("localhost", "root", "123") or die (mysql_error ());
mysql_select_db("popup_comment_box") or die(mysql_error());
$name=$_POST['name'];
$comment=$_POST['comment'];
$submit=$_POST['submit'];
$aut_id=$_GET['aut_id'];
if($submit){
if($name&&$comment){
$query = "INSERT INTO tbl_comments
(name, comment, timestamp, aut_id)
SELECT '$name', '$comment', NOW(), aut_id
FROM tbl_automobile
WHERE aut_id = '$aut_id' LIMIT 1";
mysql_query($query) or die(mysql_error());
echo "Your comment is successfully posted"."<br />";
}else{
echo "Please fill out all fields"."<br />";
}
}
?>
<html>
<head>
</head>
<body>
<form action="popup.php" enctype="multipart/form-data" method="post">
<table>
<tr><td>Name: <br><input type="text" name="name"/></td></tr>
<tr><td>Comment: </td></tr>
<tr><td><textarea name="comment" rows="10" cols="50"></textarea></td></tr>
<tr>
<td>
<input type='submit' name='submit' value='Comment'>
</td>
</tr>
</table>
</form>
<?php
$strSQL = "SELECT * FROM tbl_comments ORDER BY comment_id DESC";
$rs = mysql_query($strSQL) or die(mysql_error());
while($row = mysql_fetch_array($rs)){
?>
<table width="430px">
<tr>
<td colspan="2" valign="top">
<?php
echo "by "."<i>".$row['name']."</i>";
?>
</td>
</tr>
<tr>
<td valign="top">
<?php
echo $row['comment'];
?>
</td>
<td valign="top">
<?php
echo "<p align='right'>".$row['timestamp']."</p>";
?>
</td>
</tr>
<tr>
<td colspan="2" valign="top">
<?php
echo "Foreign key "."<i>".$row['aut_id']."</i>";
?>
</td>
</tr>
<hr size="1"/>
</table>
<?php } ?>
</body>
</html>