I am trying to create a simple search page as practice for later use, where i search a table "practice" with fields "name" and "married". The user should then be able to search names, and upon submitting the page should display the names alongside the marital status. My problem is this: I want the status to be a dropdown (i tried checkboxes with much difficulty, failed) with the options yes and no, and then the user may be able to change the status by selecting from the dropdown and submitting.

Right now I am having a problem with assigning names to the dropdowns. To be able to relate them to the specific record in the database I should provide them with unique names right? But I used an array and when I post it always contains only one value, the first record. Here is my code. Please tell me what I'm doing wrong.

if (isset($_POST['submitted'])){
if (isset($_POST['search'])){
	require_once ('mysql_connect.php');
	$query="SELECT * FROM practice WHERE name LIKE '%$nm%' AND married LIKE '%$st%'";
	$result=mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: ". mysql_error());
	if(@mysql_num_rows($result) > 0) {

	echo '<h2>Search Results</h2>';

	echo '<form name="results" method="POST" action="search.php">';
	echo '<table border="1" cellspacing="0" width="320">';
	echo '<tr bgcolor="#AAAAAA"><td align="center"><b><font color="#FFFFFF">Name</font></b></td><td align="center"><b><font color="#FFFFFF">Status</b></font></td></tr>';

	while($row = mysql_fetch_assoc($result)) {

	echo '<tr>';
	echo '<td> $name[$x] </td>';
	echo '<td align="center"><select name="dropdown[]">';
	echo '<option value="Yes" ';
	echo 'if ($status == "Yes"){echo "selected";}';
	echo '>Yes</option>';
	echo '<option value="No" ';
	echo 'if ($status == "No"){echo "selected";}';
	echo '>No</option></select></td>';
	echo '</tr>';


	echo '<td colspan="2" align="center"><input type="hidden" name="submitted" value="TRUE"><input type="submit" name="save" value="Save Changes"></td>';
	echo '</table>';
	echo '<br>Do another <a href="search.php">SEARCH</a>?';
	echo '</form>';

	echo '<h2>Search Results</h2>';
	echo 'No results found. Do another <a href="search.php">SEARCH</a>?';
}//closing for search
if (isset($_POST['save'])){
$y = $_POST['dropdown'];
	foreach($y as $value){	
	echo "$value<br/>";
}//closing for save
<form method="post" action="search.php">
	<table border="0">
		        <input type="text" name="name">
			<input type="text" name="status">
			<td colspan="2" align="center"><input type="submit" name="search" value="Search">
			<input type="hidden" name="submitted" value="TRUE">
<?php } ?>
9 Years
Discussion Span
Last Post by flushfire

nevermind, i figured out what was wrong. the form was posting to a older version of the file, stupid me. lol. ill be back later when i run into more problems. xD

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.