0

This the simple php code I am using to view contents of a forum. The problem is , it's working fine in one of my laptop but in second it do not show the output.

  // Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name ORDER BY id DESC";
// OREDER BY id DESC is order result by descending
$result=mysql_query($sql);
?>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td>
<td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td>
<td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td>
</tr>

<?php
while($rows=mysql_fetch_array($result)){ // Start looping table row
?>
<tr>
<td bgcolor="#E6E6E6"><? echo $rows['id']; ?></td>
<td bgcolor="#E6E6E6"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></a><BR></td>
<td align="center" bgcolor="#E6E6E6"><? echo $rows['view']; ?></td>
<td align="center" bgcolor="#E6E6E6"><? echo $rows['reply']; ?></td>
<td align="center" bgcolor="#E6E6E6"><? echo $rows['datetime']; ?></td>
</tr>

I checked everything else and they seems fine. Data is present in the database but the it's not showing in forum. Can anybody help me in this? operating sys : win7

4
  • Please post all of your code and your database structure. Commented Mar 2, 2011 at 8:49
  • I don't see where $tbl_name is defined. Are you running this code on your laptops or is it hosted elsewhere? Commented Mar 2, 2011 at 8:49
  • 1
    Maybe the short tags are disabled. Change <? echo $rows['id']; ?> to <?php echo $rows['id']; ?> and all other lines that start with <? to <?php Commented Mar 2, 2011 at 8:49
  • Are you sure, you have the same mysql installation, with the same login/password ? Commented Mar 2, 2011 at 8:50

2 Answers 2

2

time to learn debugging, pal.

Good place to start: http://www.ibm.com/developerworks/library/os-debug/

for mysql it's extremely handy to run queries this way:

$result=mysql_query($sql) or trigger_error(mysql_error()." ".$sql);

and make sure you can see all errors occurred. if you can't as a quick fix you can add these lines at the top of the script

ini_set('display_errors',1);
error_reporting(E_ALL);

but for the production state display_errors value should be changed to 0

It is also good practice to check HTML source instead of watching rendered page in the browser. It will tell you if you have any problem with short tags or not. It's always good to know if you have any problem before going to fix it.

Sign up to request clarification or add additional context in comments.

Comments

2

you should use

<?php echo $rows['id']; ?> instead of <? echo $rows['id']; ?>

short tag may be disabled.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.