Dropdown populated by mysql query - value

Hi guys,

Im just wondering of its possible to do this. I’ve created a query that displays the results as a drop down in a form. That bit seems to work OK but im having trouble figuring out how to POST that value into my processing script.

Here is the code for the form:

	       $sql = ("SELECT * FROM staff ORDER BY name ASC");
	       $query = mysql_query($sql) or die(mysql_error());
	<form name="attend" method="post" action="sick_process.php" >
		echo "<select name='staff_name'>";
			// printing the list box select command
		while ($row = mysql_fetch_array($query)) { 
			echo "<option value=$row[staff_number]>$row[name]</option>";
		/* Option values are added by looping through the array */
			echo "</select>";// Closing of list box 
	<br />
	Site: <input type="text" name="location" > <br />
	Hours: <input type="text" name="hours_worked" ><br />
	<input type="hidden" name="sick" value="1" >
	<input type="hidden" name="auth" value="1" >
	<br />
	<input type="submit" name="submit" value="Submit">

I want to be able to use the selected option in a query on the processing form, but cant figure out how to post this bit:

echo "<option value=$row[staff_number]>$row[name]</option>";

Ive tried using

$user_id = $_POST['staff_name'];

in sick_process.php but that doesnt work.

Any ideas how i can get around this?

Thanks in advance.

Well you have the logic right but possibly the values and quotes wrong.

echo '<option value="'. $row['staff_number'] .'">'. $row['name'] .'</option>';

and check the source of the page in the browser to see if the values appear.

Really? That is the way to do it. The question is, does $_POST[‘staff_name’] exist and does it have the right value?
To check that, do a print_r($_POST) at the beginning of sick_process.php


That worked an absolute treat.

I cant believe it was something so simple.

Think i need a break from the screen… its microwaving my brain…

Thanks again.

lol know that feeling :slight_smile:

as you have been so helpfull i wonder if you could shed some light on this one then please…

Its only a quick one (i hope)

In one of my queries im using

To show records only for the current week (sun-sat) how can i make it so i can see the previous week (last week)??

Whole Query:
SELECT * FROM clock_status , staff
WHERE auth = 1 and clock_status.user_id = staff.staff_number
and status = 0 and (YEARWEEK(date_time)= YEARWEEK(CURRENT_TIMESTAMP))