I’m trying this query:
//connect;
$site = mysql_real_escape_string($_GET['site']);
$data = mysql_query("SELECT * FROM Items WHERE Site = '$site'");
while($row = mysql_fetch_array( $data ))
{
print $row['type'];
}
doesn’t print anything, running SELECT * FROM Items WHERE Site = 'http://rollingstone.com/' from PHPMyAdmin returns one row.
I’m sure it must be something really basic, since I haven’t got much experience with MySQL.
I’m trying it here btw: http://www.chusmix.com/game/insert/get-items.php?site=http://rollingstone.com/
What am I doing wrong?
Make sure
$siteactually contains something; doing a quickecho $sitebefore yourmysql_query()should tell you this. If it’s empty, tryprint_r($_GET)to see if it’s in the$_GETarray. It should be, but it might not for some other reason; check any code above this snippet for stuff that modifies$_GETor$_REQUESTin any way.To request data from a MySQL table, you need to connect to the server using
mysql_connect(), then select the database withmysql_select_db(). PHP should throw errors, but to be sure put these lines at the top of your script:All errors will now be shown.
In addition, you can also test for how many rows that were returned using
mysql_num_rows(). For example:Will echo
No rowsif there weren’t any results from the query. This is all error detection code; the cause of your error isn’t obvious, so a little investigation is necessary, using the above methods (and any more you can think of).