Ok I am stumped. I am inserting the data fine into the table and database so i know its not the config.php nor opendb.php. I used a code like this before and it work, i've only altered the $sql, the td's, and the $rows[]. Table name is hotspots (all lower case) all of the column names are lower case also. Column names are id, topic, comment, username, timestamp. Here's the code.

$sql="SELECT * FROM hotspots ORDER BY id DESC";
$result=mysql_query($sql);
 
 
$color="1";
 
echo '<table width="472px" border="0" align="center" cellpadding="2" cellspacing="0" style="border:1px solid #0000ff;">';
while($rows=mysql_fetch_array($result)){
 
if($color==1){
 
echo "<tr bgcolor='#6698FF' >
<td style='border-top:1px solid #0000ff; color:#000000;font-weight: bold;'>".$rows['username']."</td><td style='border-top:1px solid #0000ff; text-align: right;color:#000000;font-weight: bold;'>".$rows['timestamp']."</td></tr>
<tr bgcolor='#6698FF' style='border-bottom:1px solid #0000ff;color:#000000;font-weight: bold;'><td style=''>".$rows['topic']."</td><td style='text-align: right;color:#000000;font-weight: bold;'>".$rows['timestamp']."</td>
</tr><tr bgcolor='#6698FF'><td colspan='2' bgcolor='#6698FF'></td></tr><tr bgcolor='#6698FF'><td colspan='2' bgcolor='#6698FF'></td></tr><tr bgcolor='#6698FF'; style='border-bottom:1px solid #0000ff;' color:#000000;font-weight: bold;'><td colspan='2' style='color:#ffffff;font-weight: bold;font-size:13px;''>".$rows['comment']."</td>
</tr><tr bgcolor='#6698FF'><td style='border-bottom:1px solid #0000ff;' colspan='2' bgcolor='#6698FF'></td></tr>";
$color="2";
 
} else {
 
echo "<tr bgcolor='#AFDCEC'>
<td style='border-top:1px solid #0000ff;color:#0000ff;font-weight: bold;'>".$rows['username']."</td><td style='border-top:1px solid #0000ff; text-align: right;color:#0000ff;font-weight: bold;'>".$rows['timestamp']."</td></tr>
<tr bgcolor='#AFDCEC' style='border-bottom:1px solid #0000ff;color:#0000ff;font-weight: bold;'><td style=''>".$rows['topic']."</td><td style='text-align: right;color:#0000ff;font-weight: bold;'>".$rows['timestamp']."</td>
</tr><tr bgcolor='#AFDCEC'><td colspan='2' bgcolor='#AFDCEC'></td></tr><tr bgcolor='#AFDCEC'><td colspan='2' bgcolor='#AFDCEC'></td></tr><tr bgcolor='#AFDCEC' style='border-bottom:1px solid #0000ff;color:#0000ff;font-weight: bold;'><td colspan='2' style='color:#0000ff;font-weight: bold;font-size:13px;'>".$rows['comment']."</td>
</tr><tr bgcolor='#AFDCEC'><td style='border-bottom:1px solid #0000ff;' colspan='2' bgcolor='#AFDCEC'></td></tr>";
$color="1";
}

}
echo '</table>';

Dani AI

Generated

Short expert note: the problem ended up being an output/parse issue rather than a failed insert. The reply from traced it to the PHP tag style used in the view file; on some local/server PHP installs the short echo form is not enabled, so PHP never emitted the rows even though the database inserts succeeded. That explains why nothing showed despite a successful insert.

Quick, durable debugging checklist (for future readers and similar setups):

  • Enable PHP error reporting and check the web server/PHP error logs so parse/runtime problems aren’t silently suppressed.
  • Verify the database include/connection actually runs before the SELECT and that the query executed successfully (inspect the query result and the returned row count).
  • Confirm table and field identifiers match exactly; table name case can matter on some systems.
  • Avoid relying on short PHP open tags in portable code; either enable the short-tag option in php.ini or use the full PHP opening form so output is consistent across environments.
  • Keep presentation separate: move styles into CSS and keep PHP focused on data/output. That makes debugging and maintenance easier, as and suggested.

Additional, longer-term advice: the code in this thread uses the legacy mysql extension and inline output. For any production or future work, migrate to mysqli or PDO with parameterized queries to prevent SQL injection, and always escape HTML output to prevent XSS. Also standardize UTF-8 handling and enable logging on the deployment server so similar problems are caught quickly.

This thread illustrates three common traps for local development: config differences (PHP settings), silent error suppression, and older API usage. The combination of straightforward debugging steps and a plan to modernize the stack will prevent the same surprise later on.

Recommended Answers

All 10 Replies

Instead of assuming there are people on this forum who can simulate your server in their heads, could you maybe post what it is that is actually going wrong? Any errors?

Member Avatar for Member #671080

Hi RazorRamon,

You really should put all that styling into a css file (or at the top of the document) to keep your code clean.

What is the actual problem you are having though? Are you getting any error messages?

edit: Sorry Insensus, I didn't notice your post as I type slow :)

This is the HTML code that calls the code above. I titled the code above viewcomments.php. I haven't uploaded this website, right now I am only testing it on wamp. There are no errors it just doesn't display what is in the table. I currently only have one entry in the table that I inserted using this HTML code and inserttopic.php that the form is directed to use. inserttable.php also uses config2.php and opendb.php to connect to the database which is why I know that is not the issue. Sorry Zagga I know the code is sloppy.

<html>

 
<body>
 
 

 


<DIV >
<table width="480" BACKGROUND="images/commentback.jpg">
     <tr>
         <td>             
             <form method="post" action="inserttopic.php">
              <span class="whitetitle"><br>Topic:<br> <input name="topic" type="text" STYLE="background: white; border: 1px #000000 solid;"><br >
              Username:<br><input name="username" type="text" STYLE="background: white; border: 1px #000000 solid;"><br >
	Comment:<br >
              <textarea name="comment" rows="4" cols="55" STYLE="background: white; border: 1px #000000 solid;">250 char. max</textarea><br >
              <input type="submit" value="send"></span>
              </form>
         </td>
     </tr>
</table>
</div>
<br><br>
 
<?php
include 'config2.php';
include 'opendb.php';
include 'viewcomments.php';
include 'closedb.php';
?>

 
 

</body>
 
 
</html>
Member Avatar for Member #671080

Are you sure the data is stored in the database correctly?

Try adding print_r($rows); to line 10 of viewcomments.php (after the while statement) to see if you are getting a result array.

I tried

print_r($rows);

no luck. I have a question though, do i need to set $rows to something before using it?

$result= mysql_query("SELECT * FROM `hotspots` ORDER BY `id` DESC")or die (mysql_error());
$color="1";
echo '<table width="472px" border="0" align="center" cellpadding="2" cellspacing="0" style="border:1px solid #0000ff;">';
while($rows=mysql_fetch_array($result)){
if($color==1){
?>
<tr bgcolor='#6698FF' >
<td style='border-top:1px solid #0000ff; color:#000000;font-weight: bold;'><? echo $rows[username]; ?></td><td style='border-top:1px solid #0000ff; text-align: right;color:#000000;font-weight: bold;'><? echo $rows[timestamp]; ?></td></tr>
<tr bgcolor='#6698FF' style='border-bottom:1px solid #0000ff;color:#000000;font-weight: bold;'><td style=''><? echo $rows[topic]; ?></td><td style='text-align: right;color:#000000;font-weight: bold;'><? echo $rows[timestamp]; ?></td>
</tr><tr bgcolor='#6698FF'><td colspan='2' bgcolor='#6698FF'></td></tr><tr bgcolor='#6698FF'><td colspan='2' bgcolor='#6698FF'></td></tr><tr bgcolor='#6698FF'; style='border-bottom:1px solid #0000ff;' color:#000000;font-weight: bold;'><td colspan='2' style='color:#ffffff;font-weight: bold;font-size:13px;''><? echo $rows[comment]; ?></td>
</tr><tr bgcolor='#6698FF'><td style='border-bottom:1px solid #0000ff;' colspan='2' bgcolor='#6698FF'></td></tr>
<? 
$color="2";
}else{ ?>
<tr bgcolor='#AFDCEC'>
<td style='border-top:1px solid #0000ff;color:#0000ff;font-weight: bold;'><? echo $rows[username]; ?></td><td style='border-top:1px solid #0000ff; text-align: right;color:#0000ff;font-weight: bold;'><? echo $rows[timestamp]; ?></td></tr>
<tr bgcolor='#AFDCEC' style='border-bottom:1px solid #0000ff;color:#0000ff;font-weight: bold;'><td style=''><? echo $rows[topic]; ?></td><td style='text-align: right;color:#0000ff;font-weight: bold;'><? echo $rows[timestamp]; ?></td>
</tr><tr bgcolor='#AFDCEC'><td colspan='2' bgcolor='#AFDCEC'></td></tr><tr bgcolor='#AFDCEC'><td colspan='2' bgcolor='#AFDCEC'></td></tr><tr bgcolor='#AFDCEC' style='border-bottom:1px solid #0000ff;color:#0000ff;font-weight: bold;'><td colspan='2' style='color:#0000ff;font-weight: bold;font-size:13px;'><? echo $rows[comment]; ?></td>
</tr><tr bgcolor='#AFDCEC'><td style='border-bottom:1px solid #0000ff;' colspan='2' bgcolor='#AFDCEC'></td></tr>
<? 
$color="1";
}
}
echo'</table>';

Try that - I didn't see anything immediately wrong with it though.

Member Avatar for Member #671080

$result is an array containing all the data returned that matched your query.
$rows runs through a while loop. It is an array that takes the first result of the query (1 row), then moves on to the next row, then the next until there are no more rows.

I haven't gone through your code thoroughly but it looks like it should work if you have some data to display.

If the print_r statement didn't display a result, it looks like nothing was retrieved from the database.

Check whether shorthand is enabled on your server otherwise....the code

<? echo $rows[username]; ?>

won't work....
If it is not enabled then write like this

<?php echo $rows[username]; ?>

Great IIM!!! thanks it worked!!! thanks for all the help everybody..

If your problem is solved mark the thread as solved!!!

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.