-3

Here is my code I have no error but no data shown on my page. Some help please...what is wrong on my code? Thank you so mucH

<?php 
            if(logged_in() === true){

            $q=mysql_query("select *  from `admin` order by `id` desc");

            echo "<table cellspacing=0 cellpadding=0 border=1><tr><td>Id</td><td>User</td><td>Password</td><td>Permission</td><td>delete</td><td>edit</td></tr>";

            while($date=mysql_fetch_row($q));
            echo "<tr><td>{$date[0]}</td><td>{$date[1]}</td><td>{$date[2]}</td><td>{$date[3]}</td><form method=post action=delete.php><td><input type=hidden name=id value='{$date[0]}'><input type=submit name=sterge value=delete></td></form><form action=edit.php method=get><td><input type=hidden name=id value='{$date[0]}'><input type=submit name=edit value=edit></td></td></form></tr>";

            echo "</table>";    

            }else {

            include 'includes/widgets/home.php';
            }

 ?>
aleo
  • 43
  • 5
  • Any error message? PHP can have a lot of different things going wrong so you'll need to activate warnings and debug info to find out what's going on. – alcfeoh Sep 21 '15 at 17:57
  • If you can, you should [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really not hard](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Sep 21 '15 at 18:00
  • 1
    Add error reporting to the top of your file(s) right after your opening ` – Jay Blanchard Sep 21 '15 at 18:01
  • *They wouldn't know what to do with that Sam, even if it came with an one-step instructional manual*. - @JayBlanchard – Funk Forty Niner Sep 23 '15 at 11:29

2 Answers2

3

A few things, as with the below changes, it works with data coming back. I faked the logged_in() function by always returning true.

First thing, you had a semi-colon after your while right away. So that was bad. I put the ending </table> outside the while block.

Also, stay away from select *. Spell out the column names. And I suggest you use the column names and not ordinal values upon using them in the result set.

Also, move to mysqli or pdo. Jay gave you links to them above in comments.

$dbname = 'myDB';
$dbuser = 'GuySmiley';
$dbpass = 'anchovies';
$dbhost = 'localhost';
$link = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
mysql_select_db($dbname) or die("Could not open the db '$dbname'");


if(logged_in() === true){

$q=mysql_query("select *  from `admin` order by `id` desc");
if($q === FALSE) { 
    die(mysql_error()); // this is for non-production code
}


echo "<table cellspacing=0 cellpadding=0 border=1><tr><td>Id</td><td>User</td><td>Password</td><td>Permission</td><td>delete</td><td>edit</td></tr>";

while($date=mysql_fetch_row($q)) 
{
    echo "<tr><td>{$date[0]}</td><td>{$date[1]}</td><td>{$date[2]}</td><td>{$date[3]}</td><form method=post action=delete.php><td><input type=hidden name=id value='{$date[0]}'><input type=submit name=sterge value=delete></td></form><form action=edit.php method=get><td><input type=hidden name=id value='{$date[0]}'><input type=submit name=edit value=edit></td></td></form></tr>";
}
echo "</table>";
}
else {
    echo "you are not logged in<br>";
}

enter image description here

So it outputs your data (and by turning on error reporting, developing code is a lot easier).

Turn on error reporting

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);

Develop with non-deprecated mysql libraries with code wrapped in exception handling


By the way, schema for above test is

create table admin
(   id int auto_increment primary key,
    col1 int not null,
    col2 int not null,
    col3 int not null
);
insert admin (col1,col2,col3) values (11,111,1111),(22,222,2222);
Drew
  • 24,851
  • 10
  • 43
  • 78
  • 2
    OP ran off with my ex-wife; good. Running off with this question/answer; not good. – Funk Forty Niner Sep 22 '15 at 02:20
  • Check out the OP's track record. Plus, their new question; poor guy's in for a long haul and no green ticky to boot; not even you buddy. Sorry to be the bearer of bad news here, but at least you've got the right time 'o day ;-) – Funk Forty Niner Sep 22 '15 at 02:25
  • wasn't a total loss; you've gotten some upvotes to boot. I usually check OP's track record first. Most of the time, you tell 'em how to close a question and they just say *"Meh.... f * ck it"*. – Funk Forty Niner Sep 22 '15 at 02:30
  • Some of them honestly don't know how Stack rolls. A gentle push in the right direction usually helps and many do do the right thing, while the sponges just keep on soaking it up. – Funk Forty Niner Sep 22 '15 at 02:36
1

Kind of looks like

while($date=mysql_fetch_row($q));
       echo "<tr><td>{$date[0]}</td><td>{$date[1]}</td><td>{$date[2]}</td><td>{$date[3]}</td><form method=post action=delete.php><td><input type=hidden name=id value='{$date[0]}'><input type=submit name=sterge value=delete></td></form><form action=edit.php method=get><td><input type=hidden name=id value='{$date[0]}'><input type=submit name=edit value=edit></td></td></form></tr>";

        echo "</table>"; 

Should be

while($date=mysql_fetch_row($q)){
        echo "<tr><td>{$date[0]}</td><td>{$date[1]}</td><td>{$date[2]}</td><td>{$date[3]}</td><form method=post action=delete.php><td><input type=hidden name=id value='{$date[0]}'><input type=submit name=sterge value=delete></td></form><form action=edit.php method=get><td><input type=hidden name=id value='{$date[0]}'><input type=submit name=edit value=edit></td></td></form></tr>";

        echo "</table>"; 
}

Note the semicolon instead of the braces for the while loop

user2879041
  • 1,077
  • 1
  • 12
  • 25