Problem with Notice: Undefined index
I have a problem with the following code fragment:
<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>"
?>
After calling this code, shall开发者_JAVA百科 receive the following error message: "NOTICE: UNDEFINED INDEX: QUERYSELECT"
Please help me.
You are sending the data as POST, but attempting to fetch it from GET.
$querySelect = $_GET['querySelect'];
should be
$querySelect = $_POST['querySelect'];
and better yet,
$querySelect = !empty($_POST['querySelect']) ? $_POST['querySelect'] : null;
Replace GET by POST in the following line:
$querySelect = $_GET['querySelect'];
精彩评论