Page 1 of 1

something weird happens

Posted: Sat Sep 12, 2009 7:45 pm
by denniss
okay, so i was trying to have this php code prints out everything on my database and next to it, i would have a link that would remove that entry from the database.

Here is the code

Code: Select all

<?php
    $username ='dennis';
    $password ='dindan';
 
    if(!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) ||
        $_SERVER['PHP_AUTH_USER'] != $username || $_SERVER['PHP_AUTH_PW'] != $password)
    {
       header('HTTP/1.1 401 Unauthorized');
       header('WWW-Authenticate: Basic realm="Admin Page"');
       exit('You need to enter the right password');
    }
?>
<html>
    <head>
        <title></title>
    </head>
    <body>
    <?php
            $dbc = mysqli_connect ('localhost','root','','cp5');
            $query = "SELECT * FROM cptable";
            $result = mysqli_query($dbc,$query);
            $i = 0;
            while($row = mysqli_fetch_array($result)){
                echo $i;
                echo $row['name'] . '       ' . $row['score'] .'        '. 
                    '<a href="confirmation.php?name='.$row['name'].'&score='.$row['score'].'>  Remove </a> <br/>';
                $i++;
            }
            mysqli_close($dbc);
    ?>
    </body>
</html>
 
And This is how my table looks like
mysql> select * from cptable;
+----------+------------+--------------------------+--------------+
| name | score | description | logo |
+----------+------------+--------------------------+--------------+
| dorkass | 3434 | i dork | |
| monkey | 3434 | i love banana | |
| dingdong | 3434 | man this sux | verified.gif |
| gamogamo | 435435 | dude i love sleeping too | verified.gif |
| dennis | 12312 | love sleep | verified.gif |
| saru | 3434 | banana suki dayo | |
| dududt | 99999 | i love 999 | |
| doraemon | 2147483647 | dorayaki! | |
+----------+------------+--------------------------+--------------+
8 rows in set (0.00 sec)
For some reason the first code that I posted only showed this
0dorkass 3434 Remove
2dingdong 3434 Remove
4dennis 12312 Remove
6dududt 99999 Remove

note that it starts with 0 and then 2 and then... stops at 6... I find this very weird... can someone explain to me what's happening here?

Thank You!

Dennis

Re: something weird happens

Posted: Sat Sep 12, 2009 9:25 pm
by omika
You just need to add the final " on line 26.

From

Code: Select all

 '<a href="confirmation.php?name='.$row['name'].'&score='.$row['score'].'>  Remove </a> <br/>';
To

Code: Select all

 '<a href="confirmation.php?name='.$row['name'].'&score='.$row['score'].'">  Remove </a> <br/>';

Re: something weird happens

Posted: Sat Sep 12, 2009 9:41 pm
by denniss
owkay.... thank you so much... i feel really stupid now