I can’t get my authors from my php quotes
i have a quotes table:
id, quote, aid
i have a author table:
id, name, etc…
<?php
$DB_SERVER = "localhost";
$DB_USER = "root";
$DB_PASS = "";
$DB_NAME = "test";
$con = mysql_connect($DB_SERVER, $DB_USER, $DB_PASS);
mysql_select_db($DB_NAME);
$sql = mysql_query("SELECT * FROM quotes WHERE id = ".$_GET['id'], $con);
$row = mysql_fetch_row($sql);
$sql = mysql_query("SELECT * FROM author where aid = " . $row[1], $con);
$row = mysql_fetch_row($sql);
var_dump($row);
now i get this error
Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in /var/www/domain.com/php.php on line 14
NULL
if you
print_r($row);after the first query you will see something like:then on your second query you use
$row[1]which is the quote (string) and not the number.if you echo the error (using
mysql_error($con)) you will see something:instead of using
mysql_fetch_rowusemysql_fetch_assocand the key of the array will be the name of the column. This way, it’s very easy to retrieve data. And don’t forget to close your connection.