<?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>";
Member Avatar for Zagga

Hi darkiel21,

You forgot to say what the problem is

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?

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.

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 ";

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);
?>

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.