I have a site where I serve up random content (text, images, etc).
I have created a link that displays the mysql record id of the content encoded in the url (e.g. mysite.com/country-query.php?id=23).
My problem is that when the page loads, the url is alright, but the page is just blank.
Can you help?
below are the codes:
mysite.com/country-query.php:
<?php
define ('HOSTNAME', 'hostname');
define ('USERNAME', 'username');
define ('PASSWORD', 'password');
define ('DATABASE_NAME', 'database_name');
$db = mysql_connect(HOSTNAME, USERNAME, PASSWORD) or die ('I cannot connect to MySQL.');
mysql_select_db(DATABASE_NAME);
$query = "SELECT country_id, iso2, short_name, long_name, iso3, numcode, un_member, calling_code, cctld FROM table_name ORDER by rand() LIMIT 1";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
{
echo "<p>", "<b>", "Short Name: ", "</b>", ($row['short_name']), "</p>";
echo "<p>", "<b>", "Long Name: ", "</b>", ($row['long_name']), " ", "<b>","Calling Code: ", "</b>", ($row['calling_code']), " ", "<b>", "ccTLD: ", "</b>",($row['cctld'])," </p>";
echo "<a href='action.php?id=$row[country_id]'>NEXT COUNTRY</a>";
}
mysql_free_result($result);
mysql_close();
?>
'action.php' is where the url is displayed and the page content is supposed to show. Here is what I have in its code:
<?php
$id = mysql_escape_string($_GET['country_id']);
define ('HOSTNAME', 'hostname');
define ('USERNAME', 'username');
define ('PASSWORD', 'password');
define ('DATABASE_NAME', 'database_name');
$db = mysql_connect(HOSTNAME, USERNAME, PASSWORD) or die ('I cannot connect to
MySQL.');
mysql_select_db(DATABASE_NAME);
$query = "SELECT country_id, iso2, short_name, long_name, iso3, numcode, un_member, calling_code, cctld FROM table_name WHERE country_id = '$id' ";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
{
echo "<p>", "<b>", "Short Name: ", "</b>", ($row['short_name']), "</p>";
echo "<p>", "<b>", "Long Name: ", "</b>", ($row['long_name']), " ", "<b>", "Calling Code: ", "</b>", ($row['calling_code']), " ", "<b>", "ccTLD: ", "</b>", ($row['cctld'])," </p>";
}
mysql_free_result($result);
mysql_close();
?>
Actually, loading mysite.com/country-query.php first loads a random country, but the link on that page shows the id of that country already loaded, so what i'm trying to achieve here is to first of all load a landing page for mysite.com/country-query.php and then load the content of the link showing on that page in action.php
Thanks.
PS: there is a beginning php tag in the first line of the first code if it's not showing!