You get the undefined index when trying to get value of $_POST['forward'] when having this code:
<form name="delete" action="deleted.php" method="post">
<?php
$connect = mysql_connect("a","b","") or die("Error connecting");
mysql_select_db("c") or die("Error connecting to database");
$result = mysql_query("SELECT * FROM d ORDER BY e ASC");
echo "<select name='forward'>";
while ($row = mysql_fetch_array($result))
{
echo "<option class='class' name=" .$row['t'] . ">".$row['t'] ."</option>";
}
echo "</select><br/><br/><br/><br/>";
?>
<input type="submit" id="thisSbmit" value="Delete Contact" onClick="chck()"> <input type="button" id="cls" class="cls" value="Clear">
</form>
When doing a code like this: (I've commented out the database-part)
<form name="delete" action="deleted.php" method="post">
<?php
//$connect = mysql_connect("a","b","") or die("Error connecting");
//mysql_select_db("c") or die("Error connecting to database");
//$result = mysql_query("SELECT * FROM d ORDER BY e ASC");
$row['t'] = 1; //Dummy
echo "<select name='forward'>";
echo "<option class='class' name=" .$row['t'] . ">".$row['t'] ."</option>";
echo "</select><br/><br/><br/><br/>";
?>
<input type="submit" id="thisSbmit" value="Delete Contact" onClick="chck()"> <input type="button" id="cls" class="cls" value="Clear">
</form>
You will not recieve an undefined index-warning in your deleted.php.
With following code, you will not recieve an index-warning either.
<form name="delete" action="deleted.php" method="post">
<?php
//$connect = mysql_connect("a","b","") or die("Error connecting");
//mysql_select_db("c") or die("Error connecting to database");
//$result = mysql_query("SELECT * FROM d ORDER BY e ASC");
$row['t'] = 1; //Dummy
$row['u'] = 2; //Dummy
echo "<select name='forward'>";
echo "<option class='class' name=" .$row['t'] . ">".$row['t'] ."</option>";
echo "<option class='class' name=" .$row['u'] . ">".$row['u'] ."</option>";
echo "</select><br/><br/><br/><br/>";
?>
<input type="submit" id="thisSbmit" value="Delete Contact" onClick="chck()"> <input type="button" id="cls" class="cls" value="Clear">
</form>
AND $_POST['forward'] would actually return the name of option when no value is set. (1 or 2). BUT you SHOULD use value="" like this:
<form name="delete" action="deleted.php" method="post">
<?php
//$connect = mysql_connect("a","b","") or die("Error connecting");
//mysql_select_db("c") or die("Error connecting to database");
//$result = mysql_query("SELECT * FROM d ORDER BY e ASC");
$row['t'] = 1; //Dummy
$row['u'] = 2; //Dummy
echo "<select name='forward'>";
echo "<option class='class' value=" .$row['t'] . ">".$row['t'] ."</option>";
echo "<option class='class' value=" .$row['u'] . ">".$row['u'] ."</option>";
echo "</select><br/><br/><br/><br/>";
?>
<input type="submit" id="thisSbmit" value="Delete Contact" onClick="chck()"> <input type="button" id="cls" class="cls" value="Clear">
</form>
However, when you don't have any options in the code (commented out below), you will get an undefined Index warning.
<form name="delete" action="deleted.php" method="post">
<?php
//$connect = mysql_connect("a","b","") or die("Error connecting");
//mysql_select_db("c") or die("Error connecting to database");
//$result = mysql_query("SELECT * FROM d ORDER BY e ASC");
$row['t'] = 1; //Dummy
$row['u'] = 2; //Dummy
echo "<select name='forward'>";
//echo "<option class='class' value=" .$row['t'] . ">".$row['t'] ."</option>";
//echo "<option class='class' value=" .$row['u'] . ">".$row['u'] ."</option>";
echo "</select><br/><br/><br/><br/>";
?>
<input type="submit" id="thisSbmit" value="Delete Contact" onClick="chck()"> <input type="button" id="cls" class="cls" value="Clear">
</form>
This is because the select list contains nothing (no options).
Therefore my question: Do you actually have any options in your select-list?
Try this code, and see what echo print_r($row,true);
brings you:
<form name="delete" action="deleted.php" method="post">
<?php
$connect = mysql_connect("a","b","") or die("Error connecting");
mysql_select_db("c") or die("Error connecting to database");
$result = mysql_query("SELECT * FROM d ORDER BY e ASC");
/*debugging start
$row = mysql_fetch_array($result)
echo print_r($row,true);
debugging end */
echo "<select name='forward'>";
while ($row = mysql_fetch_array($result))
{
echo "<option class='class' value=\"" .$row['t'] . "\">".$row['t'] ."</option>";
}
echo "</select><br/><br/><br/><br/>";
?>
<input type="submit" id="thisSbmit" value="Delete Contact" onClick="chck()"> <input type="button" id="cls" class="cls" value="Clear">
</form>