我有一个网站,我提供随机内容(文字,图片等)。
我创建了一个链接,显示网址中编码内容的mysql记录ID(例如mysite.com/country-query.php?id=23)。
我的问题是,当页面加载时,网址没问题,但页面只是空白。
你能帮忙吗?
以下是代码:
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'是显示网址的位置,的网页内容应该显示。以下是我的代码:
<?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();
?>
实际上,加载mysite.com/country-query.php会首先加载一个随机国家但该页面上的链接显示该国家/地区的ID 已经加载了,所以我想在这里实现的是首先加载mysite.com/country-query.php的登录页面,然后加载显示在该页面上的链接的内容。 PHP
感谢。
PS:第一个代码的第一行有一个开始的php标记,如果没有显示的话!
答案 0 :(得分:2)
更改action.php
$id = mysql_escape_string($_GET['country_id']);
到
$id = mysql_escape_string($_GET['id']);
country-query.php 中的OR
echo "<a href='action.php?id=$row[country_id]'>NEXT COUNTRY</a>";
到
echo "<a href='action.php?country_id=$row[country_id]'>NEXT COUNTRY</a>";
您似乎对参数名称感到困惑