PHP MYSQL insert problem.?

Dannnn!

New member
Whats wrong with it, config.php is correct and i can connect to the databace.

<?php
include("config.php");
$tbl_name="news"; // Table name

// Retrieve data from database
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);

// Start looping rows in mysql database.
while($rows=mysql_fetch_array($result)){
?>

<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td width="10%"><? echo $rows['id']; ?></td>
<td width="30%"><? echo $rows['author']; ?></td>
<td width="30%"><? echo $rows['date']; ?></td>
<td width="100%"><? echo $rows['message']; ?></td>
</tr>
</table>

<?php
// close while loop
}

// close connection
mysql_close();
?>


Thanks Dan
 
If all you are trying to do is report the results of a query:

<?php
$rs = mysql_query( "SELECT * FROM news" ) or die( "Cannot parse query" );
if( mysql_num_rows($rs) == 0 ) {
echo "<p><strong>No records found.</strong></p>";
}
else {
echo "<table width=\"400\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n";
while( $row = mysql_fetch_array($rs) ) {
echo "<tr>\n";
echo "<td width=\"10%\">$row[id]</td>";
echo "<td width=\"30%\">$row[author]</td>";
echo "<td width=\"30%\">$row[date]</td>";
echo "<td width="%\">$row[message]</td>";
echo "</tr>\n";
}
echo "</table>\n";
}
?>

Note that you can't have a 100 percent width cell if you set the width of other cells.

Note that most of the attributes you are using in the table are deprecated in HTML 4 and nonexistent in XHTML 1.

Note that you do not need to explicitly close a mysql connection in PHP 4 or later, the connection is automatically closed at the end of script execution.
 
Back
Top