我有下面的代碼,並試圖使用URL中的參數來從我的數據庫中獲得匹配。我不斷收到我的錯誤消息'失敗'。讀取網址:將URL參數傳遞給PHP變量
http://www.examplesite.com/template.php?eventname=3506
代碼:
<?php
require_once("./source/include/membersite_config.php");
if(!$fgmembersite->CheckLogin())
{
$fgmembersite->RedirectToURL("login.php");
exit;
}
// Make a MySQL Connection
...
// Retrieve the variable from the url
if(!empty($_GET['eventname'])) {
$eventname = $_GET['eventname'];
} else {
//set default value for $eventname or maybe output an error because eventname isn't set
echo '<p>', 'something failed', '</p>';
}
你看過var_dump($ _GET)嗎?看起來$ _GET ['eventname']是空的。 – dmaij
[**請不要在新代碼中使用'mysql_ *'函數**](http://bit.ly/phpmsql)。他們不再被維護[並被正式棄用](https://wiki.php.net/rfc/mysql_deprecation)。看到[**紅框**](http://j.mp/Te9zIL)?學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。如果你選擇PDO,[這裏是一個很好的教程](http://j.mp/PoWehJ)。 – Kermit
很簡單,你沒有從你的表單$ _GET ['eventname']中獲得這個。因此,請檢查您的表單html以查看該字段名稱 –