Retrieve and display comments to comment table with userid, and comment

;<html>
<head></head>
<h3>All comments: </h3>
<?php

//include information required to access database
require 'authentication.inc'; 

//start a session 
session_start();

//still logged in?
if (!isset($_SESSION['db_is_logged_in'])
|| $_SESSION['db_is_logged_in'] != true) {
//not logged in, move to login page
header('Location: login.php');
exit;
} else {

//logged in 
// Connect database server	
$connection = sqlsrv_connect( $hostName, $connectionInfo )		
or die("ERROR: selecting database server failed");    
// Prepare query
$table = "comment";    
$uid = $_SESSION['userid'];
$query = "SELECT UserId,Comment FROM $table where userid = '$uid'";
	

// Execute query
$query_result = sqlsrv_query($connection, $query)
or die( "ERROR: Query is wrong");

// Output query results: HTML table
echo "<table border=1>";
echo "<tr>";
		
// fetch attribute names
foreach( sqlsrv_field_metadata($query_result) as $fieldMetadata)
echo "<th>".$fieldMetadata['Name']."</th>";
echo "</tr>";
		
// fetch table records
while ($line = sqlsrv_fetch_array($query_result, SQLSRV_FETCH_ASSOC)) {
echo "<tr>\n";
foreach ($line as $cell) {
echo "<td> $cell </td>";
}
echo "</tr>\n";
}
echo "</table>";   

// close the connection
sqlsrv_close($connection);
$comment=$_POST['comment'];
echo"<b>$comment</b><br>";
}
?>

<title>Comment Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<tr>
<form action method="post">
<td><h3> Input your new comment:</h3></td>
<td> <textarea rows="2" cols="50" name="comment"></textarea></td>
</tr>
<tr><br>
<input type="submit" value = "Submit"/>
</form>
<p><a href="main.php">Go back to main</a> </p>
</body>
</html>

this is what i have how do i save the comment and show it under the table

The script has errors,.

Add these three lines to the beginning of the page and the errors will be shown.

<?php 
error_reporting(-1);
ini_set('display_errors', 'true');

Copy, paste and search each error for solutions.

Edit:
To pause script execution add the following line

echo "line: " .__LINE__; exit.;

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.