Jump to content

Recommended Posts

i have a php page that should display results of a mysql query inside a table ... however no matter how many entries i have in the table it wont display any results only the headers any help would be great

 

i have checked and verified the login data several times over it is all correct i have just replaced them with my*** for posting.

 

i have also verified that all fields are correct and matching.

 

<html>
<head>
</head>
<body>
<form name="action" id="action" method="post" action="<?=$_SERVER['PHP_SELF']?>">
  <?
$MyUsername="myuser";
$MyPassword="mypass";
$MyDatabase="mydb";
$MyTable="mytable";

mysql_connect(localhost,$MyUsername,$MyPassword) or die( "Unable to conect to database");
@mysql_select_db($MyDatabase) or die( "Unable to select database");
if($_POST['perform']) {
foreach($_POST as $id) { 
mysql_query("DELETE FROM $MyTable WHERE ID='$id' LIMIT 1"); 
}
}
$query="SELECT * FROM $MyTable ORDER BY ID DESC" or die( "Unable to select table");
$result=mysql_query($query);
$num=mysql_numrows($result);

echo "<table width=100% border=0 align=center cellpadding=4 cellspacing=1 bordercolor=#333333 bgcolor=#FCFCFC>
<tr bgcolor=#990000>
<th height=30 align=center><span class=tab_head>Number</span></th>
<th height=30><span class=tab_head>Boat ID</span></th>
<th height=30><span class=tab_head>TS Name</span></th>
<th height=30><span class=tab_head>Boat Name</span></th>
<th height=30><span class=tab_head>First Name</span></th>
<th height=30><span class=tab_head>Last Name</span></th>
<th height=30><span class=tab_head>Boat Level</span></th>
<th height=30><span class=tab_head>Pirate Level</span></th>
<th height=30><span class=tab_head>Current EP</span></th>
<th height=30><span class=tab_head>Current Guild</span></th>
<th height=30><span class=tab_head>Join Shy?</span></th>
<th height=30><span class=tab_head>Country</span></th>
<th height=30><span class=tab_head>Other Boats</span></th>
<th height=30><span class=tab_head>Comments</span></th>
<th height=30><span class=tab_head>IP</span></th>
</tr>\n";
while($row=mysql_fetch_array($result))
{
echo "<tr bgcolor=#2F2F2F>\n";
echo "\n<td align=center>". $row['ID'] . "<input type=checkbox name=". $row['ID'] . " id=". $row['ID'] . " value=". $row['ID'] . " /></td>";
echo "\n<td>". $row['tagid'] . "</td>";
echo "\n<td>". $row['tsname'] . "</td>";
echo "\n<td>". $row['boatname'] . "</td>";
echo "\n<td>". $row['firstname'] . "</td>";
echo "\n<td>". $row['lastname'] . "</td>";
echo "\n<td>". $row['blevel'] . "</td>";
echo "\n<td>". $row['plevel'] . "</td>";
echo "\n<td>". $row['ep'] . "</td>";
echo "\n<td>". $row['guild'] . "</td>";
echo "\n<td>". $row['country'] . "</td>";
echo "\n<td>". $row['interested'] . "</td>";
echo "\n<td>". $row['otherboats'] . "</td>";
echo "\n<td>". $row['comments'] . "</td>";
echo "\n<td>". $row['ip'] . "</td>";
echo "\n</tr>";
}
echo "\n</table>\n";

mysql_close();
?>
  <input type="submit" name="perform" id="perform" value="Delete Selected" />
</form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/155467-php-not-displaying-mysql-data/
Share on other sites

Well, it seems as though the SQL is not returning any data, hence the header only being displayed.

 

Do an echo $query; and see what is being displayed. Then, copy the SQL and put it into PHPMYADMIN query analyzer and work out the sql statement.

 

Also, temporarily remove the delete sql and try it again.

ok i did the echo $query; and now the page is blank i tried to add it at the bottom just before the mysql_close(); tag and it was blank not even the header, then i tried to add it just after the inital query, again blank page and no header.... i know that the sql is correct due to the information is being input into the db .... :-[  ??? im so confused as to what the issue could be....

adding the information that u suggested resulted in a blank page as well.

 

perhaps it will help if i explain what i was trying to accomplish, i am trying to have this page show the results in a table format with headers of all records in the DB and in each row have a check box that when selected and the button pressed will delete only the selected rows from the DB. Now mind you i am no expert in php nor sql but i belive that i have all the correct syntax i have double and triple checked the code and cannot find any mistakes any where.

 

i know it is connecting and selecting the correct DB and TABLE due to no reply from the or die( "Unable to select database");

 

Again here is the code i have made a few slight modifications...

 

<html>
<head>
</head>
<body>
<form name="action" id="action" method="post" action="<?=$_SERVER['PHP_SELF']?>">
  <?
$MyUsername="#######";
$MyPassword="#######";
$MyDatabase="#######";

mysql_connect(#######,$MyUsername,$MyPassword) or die( "Unable to conect to database");
@mysql_select_db($MyDatabase) or die( "Unable to select database");
if($_POST['perform']) {
foreach($_POST as $id) { 
mysql_query("DELETE FROM 'join' WHERE ID='$id' LIMIT 1"); 
}
}
$query=SELECT * FROM 'join' ORDER BY ID DESC or die( "Unable to select table");
$result=mysql_query($query);
$num=mysql_numrows($result);

echo "<table width=100% border=0 align=center cellpadding=4 cellspacing=1 bordercolor=#333333 bgcolor=#FCFCFC>
<tr bgcolor=#990000>
<th height=30 align=center><span class=tab_head>Number</span></th>
<th height=30><span class=tab_head>Boat ID</span></th>
<th height=30><span class=tab_head>TS Name</span></th>
<th height=30><span class=tab_head>Boat Name</span></th>
<th height=30><span class=tab_head>First Name</span></th>
<th height=30><span class=tab_head>Last Name</span></th>
<th height=30><span class=tab_head>Boat Level</span></th>
<th height=30><span class=tab_head>Pirate Level</span></th>
<th height=30><span class=tab_head>Current EP</span></th>
<th height=30><span class=tab_head>Current Guild</span></th>
<th height=30><span class=tab_head>Join Shy?</span></th>
<th height=30><span class=tab_head>Country</span></th>
<th height=30><span class=tab_head>Other Boats</span></th>
<th height=30><span class=tab_head>Comments</span></th>
<th height=30><span class=tab_head>IP</span></th>
</tr>\n";
while($row=mysql_fetch_array($result))
{
echo "<tr bgcolor=#2F2F2F>\n";
echo "\n<td align=center>". $row['ID'] . "<input type=checkbox name=". $row['ID'] . " id=". $row['ID'] . " value=". $row['ID'] . " /></td>";
echo "\n<td>". $row['tagid'] . "</td>";
echo "\n<td>". $row['tsname'] . "</td>";
echo "\n<td>". $row['boatname'] . "</td>";
echo "\n<td>". $row['firstname'] . "</td>";
echo "\n<td>". $row['lastname'] . "</td>";
echo "\n<td>". $row['blevel'] . "</td>";
echo "\n<td>". $row['plevel'] . "</td>";
echo "\n<td>". $row['ep'] . "</td>";
echo "\n<td>". $row['guild'] . "</td>";
echo "\n<td>". $row['country'] . "</td>";
echo "\n<td>". $row['interested'] . "</td>";
echo "\n<td>". $row['otherboats'] . "</td>";
echo "\n<td>". $row['comments'] . "</td>";
echo "\n<td>". $row['ip'] . "</td>";
echo "\n</tr>";
}
echo "\n</table>\n";

mysql_close();
?>
  <input type="submit" name="perform" id="perform" value="Delete Selected" />
</form>
</body>
</html>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.