MySQL Forums
Forum List  »  PHP

Re: GEtting the value of a selected listbox item
Posted by: Barry Galbraith
Date: June 26, 2013 09:44PM

Is this what you mean?

<?php

//Establish connection


$query = "SELECT Matric_No FROM civil_2005_2006_sem1_yr1" ;
$sql = mysql_query($query) or die (mysql_error());

print "<p>Select MatNo: \r\n";
print "<form name=\"form1\" id=\"form1\" action=\"action.php\" method=\"post\" >
print "<select name=\"MatricNo\" > \r\n";

while ($row = mysql_fetch_array($sql))
{
$Matric_No = $row["Matric_No"];
// Echo your rows here...
print "<option value=\"$Matric_No\">$Matric_No</option>\r\n";
}
print "</select>\n";
print "<input type=\"submit\" value=\"submit\" name=\"submit\">";
print "</form>";

>?

For a html form to "send" any data the input fileds have to be contained in a FORM element.

The control(s) contents are then either sent in $_GET or $_POST , depending on the method attribute of the form. My example is POST, and the file the data is sent to is named in the action attribute. My example sends data to a file I've named action.php, and here it is.
<?php

if ($_POST) {
	$Matric_No_Data = $_POST['Matric_No'];  // Matric_No was the name of the SELECT box in the previous file
	echo "Matric_No selected was $Matric_No_Data<br>";
	}
else {
	echo "No data received<br>";
	}
?>

Good luck,
Barry.

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.