0
<?php
echo "<html>
<head><title>comment box</title></head>
<body>
<hr width=1000>";

require('connect.php');


if(isset($_POST['submit']))
{
    $name = $_POST['name'];
    $comment = $_POST['comment'];

    echo "<font color=white><center>";
      $result= mysql_query(" INSERT INTO COMMENT (name,comment) VALUES ('$name','$comment')") 
                or die(mysql_error());

    while($row = mysql_fetch_array($result)) {

               echo "<tr> <th>ID</th> <th>Name</th> <th>Comment</th></tr>";
                echo "<tr>";
                echo '<td>' . $row['name'] . '</td>';
                echo '<td>' . $row['comment'] . '</td>';

                echo "</tr>"; 
        } 


    echo "</font></center>";
    echo "</table>";
}



echo "<center>
<form method='POST' action='photogallery.php'>
   <font color=white>Name</font><input type='text' name='name'><br>
   <font color=white>Comment</font><textarea cols=30 rows=5 name='comment'></textarea><br>
   <input type='submit' name='submit' value='Comment'><br>
</form>
</center>

</center>
</body></html>";

Edited by Dani: Formatting fixed

4
Contributors
6
Replies
11
Views
5 Years
Discussion Span
Last Post by karthik_ppts
0

Hi darkiel21,

You forgot to say what the problem is

...
the problem is : the name and comment does not display but it goes to my mysql database.. what should i do?

0

Hi, well, just by looking at it, you will need to ECHO out everything, including the form as well. You cannot end with

</html>";

without echo and please use CODE tags.

Edited by SQLpower: n/a

0

Hi, well, just by looking at it, you will need to ECHO out everything, including the form as well. You cannot end with

</html>";

without echo and please use CODE tags.

please observe that there is a echo in there and it will also display it as long as there is a ";

Edited by darkiel21: wrong grammar

-1

Is this what you want?

<?php
echo "<html>";
echo "<head><title>comment box</title></head>";
echo "<body>";
echo "<hr width=1000>";



$conn = mysql_connect("localhost", "root", "") or die (mysql_error()); 
mysql_select_db("stuff") or die (mysql_error());


if(isset($_POST['submit']))
{
$name = $_POST['name'];
$comment = $_POST['comment'];



echo "<font color=white><center>";
$result= mysql_query(" INSERT INTO COMMENT (name,comment) VALUES ('$name','$comment')")
or die(mysql_error());

if($result === FALSE) 
{
    die(mysql_error()); 
}

while($row = mysql_fetch_array($result)) 
{
echo "<tr> <th>ID</th> <th>Name</th> <th>Comment</th></tr>";
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['comment'] . "</td>";

echo "</tr>";
}


echo "</font></center>";
echo "</table>";
}



echo "<center>";
echo "<form method='POST' action='photogallery.php'>";
echo "<font color=white>Name</font><input type='text' name='name'><br>";
echo "<font color=white>Comment</font><textarea cols=30 rows=5 name='comment'></textarea><br>";
echo "<input type='submit' name='submit' value='Comment'><br>";
echo "</form>";
echo "</center>";

echo "</center>";
echo "</body>";
echo "</html>"; 

mysql_close($conn);
?>

Edited by SQLpower: n/a

0

You can't extract data from insert query resultset using mysql_fetch_array. Use select query to extract the data.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.