我沒有太多的經驗......幫助是非常感謝。
$ id = $ _GET [「categoryID」];不設置變量。
$ _GET [「categoryID」]正在返回值,但該變量未被設置。
我可以通過使用$ id = 3來設置變量;然而$ id = $ _GET [「categoryID」];不起作用。
<?php
if (@$_REQUEST['ajax']) {
$link = $nm3;
if ($link == false)
trigger_error('Connect failed - ' . mysql_error(), E_USER_ERROR);
$connected = mysql_select_db('dgp', $link);
if ($connected) {
$id = $_GET["categoryID"];
$results = mysql_query('select * from selectMenu where categoryID= \'' . $id . '\' AND category="' . strtolower(mysql_real_escape_string(strip_tags($_REQUEST['category']))) . '"');
$json = array();
while (is_resource($results) && $row = mysql_fetch_object($results)) {
//$json[] = '{"id" : "' . $row->id . '", "label" : "' . $row->label . '"}';
$json[] = '"' . $row->label . '"';
}
echo '[' . implode(',', $json) . ']';
die(); // filthy exit, but does fine for our example.
} else {
user_error("Failed to select the database");
}
}
?>
好了,我剝都記錄下來,據我知道怎麼辦。看來問題可能與ajax請求有關。
這是使用$ _GET .... $ id = $ _ GET [「categoryID」]的精簡代碼。它打印$ _GET [「categoryID」]結果和$ id。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test $_GET</title>
</head>
<body>
<?php
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$id = $_GET["categoryID"];
}
?>
print_r($_GET) = <?php print_r($_GET); ?>
<br />
print_r($id) = <?php print_r($id); ?>
</body>
</html>
這裏是帖子頁樣本....
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>testPOST</title>
</head>
<body>
<form action="testPOST.php" method="post">
categoryID: <input type="text" name="categoryID" /><br />
<input type="submit" value="Submit" />
</form>
</body>
</html>
和後結果頁面...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test $_POST</title>
</head>
<body>
<?php
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$id = $_POST["categoryID"];
}
?>
print_r($_POST) = <?php print_r($_POST); ?>
<br />
print_r($id) = <?php print_r($id); ?>
</body>
</html>
它仍然是不設置$ id = $ _GET [「categoryID」];即使是在請求塊之外打印它再次感謝您的幫助。
你是什麼意思*「$ _ GET [」categoryID「]正在返回值,但該變量沒有被設置。」*?你如何驗證這個?實際上需要多少代碼來重現問題? –
jQuery在哪裏發揮作用? – Imp
如果我使用$ id = 2,則查詢成功。如果我使用$ id = $ _ GET [「categoryID」],即使print_r($ _ GET);查詢失敗。返回數組([categoryID] => 2) – John