I want to be able to change variables without my submit button activating. if that's possible. im fairly new to php so if this is stupid please bear with me. =P
These are my two problems right now: I want to change variables on the onchange of the dropdown, and I'm having problems relating the dropdown to the specific record it should be asigned to.
I have tried the first code example, It shows an input box, I dont want the user to input names. Ive also tried assigning an array in place of that input box, but Im having trouble making it work when posting. The second code example I prefer, but then I'm having trouble relating the data from the dropdowns to the records in the database. anyways, after trying to make this work using checkboxes (and failing) this is the code I am stuck with:
<?php
if (isset($_POST['submitted'])){
$nm=$_POST['name'];
$st=$_POST['status'];
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 "<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)) {
$name=$row["name"];
$status=$row["married"];
echo "<tr>";
echo "<td> $name </td>";
echo "<td align=\"center\"><select name=\"status\">";
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 "</table>";
echo "<br>Do another <a href=\"search.php\">SEARCH</a>?";
}else{
echo "<h2>Search Results</h2>";
echo "No results found. Do another <a href=\"search.php\">SEARCH</a>?";
}
}else{
?>
<h2>Search</h2>
<form method="post" action="search.php">
<table border="0">
<tr>
<td>Name</td>
<td>
<input type="text" name="name">
</td>
</tr>
<tr>
<td>Status</td>
<td>
<input type="text" name="status">
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="hidden" name="submitted" value="TRUE">
<input type="submit" name="submit" value="Search">
</td>
</tr>
</table>
</form>
<?php } ?>
What should I add to get the dropdowns to relate to the specific columns in the database?