I'm new to php.
When I run this script I get the error message:
Undefined offset: 0
for the line: while ($row = mysql_fetch_assoc($result)) { echo $row['0'];
    <?php
    if (!$link = mysql_connect('localhost', 'root', '')) {
        echo 'Could not connect to mysql';
        exit;
    }
    if (!mysql_select_db('first_db', $link)) {
        echo 'Could not select database';
        exit;
    }
    $sql    = 'SELECT * FROM users WHERE id = 3';
    $result = mysql_query($sql, $link);
    if (!$result) {
        echo "DB Error, could not query the database\n";
        echo 'MySQL Error: ' . mysql_error();
        exit;
    }
    while ($row = mysql_fetch_assoc($result)) {
        echo $row['0'];
    }
    mysql_free_result($result);
    ?>
Here is another script which connects to the database, here the syntax $row['0'] is working.
<?php
//Step1
 $db = mysqli_connect('localhost','root','','first_db')
 or die('Error connecting to MySQL server.');
?>
<html>
 <head>
 </head>
 <body>
 <h1>PHP connect to MySQL</h1>
<?php
//Step2
$query = "SELECT * FROM  users";
mysqli_query($db, $query) or die('Error querying database.');
//Step3
$result = mysqli_query($db, $query);
//$row = mysqli_fetch_array($result);
while ($row = mysqli_fetch_array($result)) {
 echo $row[0] . ' ' . $row[1] . ': '. $row[2] .'<br />';
}
//Step 4
mysqli_close($db);
?>
</body>
</html>
How come the syntax row['0'] works for the second script but not the first ?
btw my database is called first_db and the table called users. It has 3 columns; named id, username, and password.
 
     
     
    