これについてはあまり経験がありません...助けていただければ幸いです。
$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"]; はまだ設定されていません。リクエストブロックの外に出力していますが、ご協力いただきありがとうございます。