wantabe2
asked on
PHP Not Displaying Data
Can someone else eyeball this code to see if you can tell me why it is not displaying the mysql data in a browser?
<?php
$host="localhost"; // Host name
$username="user"; // Mysql username
$password="password"; // Mysql password
$db_name="test"; // Database name
$tbl_name="test_mysql"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td colspan="4"><strong>List data from mysql </strong> </td>
</tr>
<tr>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Lastname</strong></td>
<td align="center"><strong>Email</strong></td>
<td align="center"><strong>Update</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><? echo $rows['name']; ?></td>
<td><? echo $rows['lastname']; ?></td>
<td><? echo $rows['email']; ?></td>
// link to update.php and send value of id
<td align="center"><a href="update.php?id=<? echo $rows['id']; ?>">update</a></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
</table>
<?php
mysql_close();
?>
Line 13 - how do you know whether that query worked?
Code works fine for me.
I assume you are not seeing any errors, and make sure you have data on the table ;)
On another note, you have a // comment in the in the HTML
I assume you are not seeing any errors, and make sure you have data on the table ;)
On another note, you have a // comment in the in the HTML
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL^E_NO TICE);
?>
Place this code in the top of the script, this will show up the actual error in the script, later you can disable this code.
Hope this helps
ini_set('display_errors', 1);
error_reporting(E_ALL^E_NO
?>
Place this code in the top of the script, this will show up the actual error in the script, later you can disable this code.
Hope this helps
This code works perfectly fine for me .
Please add this code at the top of you page and check
Please add this code at the top of you page and check
ini_set('error_reporting',E_ALL);
ini_set('display_startup_errors','On');
ini_set('display_errors','On');
123.JPG
Hi,
please paste the o/p of the code below
please paste the o/p of the code below
<?php
$host="localhost"; // Host name
$username="user"; // Mysql username
$password="password"; // Mysql password
$db_name="test"; // Database name
$tbl_name="test_mysql"; // Table name
ini_set('error_reporting',E_ALL);
ini_set('display_startup_errors','On');
ini_set('display_errors','On');
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td colspan="4"><strong>List data from mysql </strong> </td>
</tr>
<tr>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Lastname</strong></td>
<td align="center"><strong>Email</strong></td>
<td align="center"><strong>Update</strong></td>
</tr>
<?php
while($rows=mysql_fetch_assoc($result)){
echo "<pre>";print_r($row);exit;
?>
<tr>
<td><?php echo $rows['name']; ?></td>
<td><?php echo $rows['lastname']; ?></td>
<td><?php echo $rows['email']; ?></td>
// link to update.php and send value of id
<td align="center"><a href="update.php?id=<? echo $rows['id']; ?>">update</a></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
</table>
<?php
mysql_close();
?>
srry instead or row it should be print_r(rows);
To check whether the data is actually present in table or not
To check whether the data is actually present in table or not
Thanks for the points; it's a really good question. Another victory for data visualization! ~Ray