我遇到以下代码片段的问题:
<div class= "main2" id ="main">
<fieldset id ='fs3'>
<form action ="<?=$_SERVER['PHP_SELF']?>" method="post">
<?php
$query = pg_query($connect, "Select name FROM types") or die("");
$numrows = pg_num_rows($query);
if ($numrows > 0) {
echo "<br /><legend><center>Some Text:</center></legend><br />";
echo "<center>Some Text: <select name='querySelect'>";
while($r = pg_fetch_assoc($query)) {
echo "<option value = ".$r['name'].">".$r['name']."</option>";
}
echo "</select>\t";
echo "<input type='submit' value='submit' name='submit'>";
echo "<br />";
echo "<br />";
if (isset($_POST['submit'])) {
$querySelect = $_GET['querySelect'];
switch($querySelect)
{
case 'A':
$query = pg_query($connect, "Select model FROM urzadzenia WHERE tid=1") or die("");
break;
case 'B':
$query = pg_query($connect, "Select model FROM urzadzenia WHERE tid=2") or die("");
break;
case 'C':
$query = pg_query($connect, "Select model FROM urzadzenia WHERE tid=3") or die("");
break;
case 'D':
$query = pg_query($connect, "Select model FROM urzadzenia WHERE tid=4") or die("Zapytanie nie działa");
break;
case 'E':
$query = pg_query($polacz, "Select model FROM urzadzenia WHERE tid=5") or die("");
break;
}
}
else
echo "error";
}
echo "</form>";
echo "</fieldset>"
?>
调用此代码后,将收到以下错误消息:“注意:未定义的索引:QUERYSELECT”
请帮帮我。
答案 0 :(得分:3)
您正在以POST发送数据,但尝试从GET中获取数据。
$querySelect = $_GET['querySelect'];
应该是
$querySelect = $_POST['querySelect'];
更好,
$querySelect = !empty($_POST['querySelect']) ? $_POST['querySelect'] : null;
答案 1 :(得分:0)
在以下行中通过POST替换GET:
$querySelect = $_GET['querySelect'];