mike12255 Posted November 8, 2010 Share Posted November 8, 2010 Ive created a process which automatically creates a form for all of the "courses" that are listed in a database. This table shows the name, the course code, the current program the course is under and an option to delete the course. I have created a drop down menu for the user to select any of the current programs to switch the course into. My problem is I have X amount of select fields and radio buttons and I dont know how to tell which one has been changed below is my code, appreciate the help!: case "ep": if (isset ($_GET['id'])){ $id = $_GET['id']; echo "Below lists all of the current courses under this program. Once you have made all of the changes click the submit button at the bottom of the page. <br><br><br>"; $query = "SELECT * FROM courses WHERE cid = $id"; $result = mysql_query($query) or die (mysql_error()); echo "<form action=\"course_process.php\" method=\"post\">"; echo "<table><tr><td><strong>Course Name</strong></td><td><strong>Course Code</strong></td><td><strong>Change Course Program</strong></td><td><strong>Delete</strong></td></tr>"; $i = 0; while ($row = mysql_fetch_assoc($result)){ $r = $row['id']; $query2 = "SELECT * from catagories"; $result2 = mysql_query($query2) or die (mysql_error()); echo "<tr><td> ". $row['name']. " </td><td> ".$row['code']." </td><td><select name=\"".$row['id']."\">"; while ($row2 = mysql_fetch_assoc($result2)){ echo "<option value=".$row2['id'].">".$row2['name']. "</option>"; } echo "</select></td><td><input name=\"".$row['id']."\" type=\"radio\" value=\"Click to delete\" /></td></tr>"; } echo "<tr><td></td><td></td><td></td><td><input name=\"submit\" type=\"submit\" value=\"Commit Changes\" /> </td></tr></table></form>"; }else{ echo "Invalid action request. ERROR CODE 1"; } break; Link to comment https://forums.phpfreaks.com/topic/218144-how-to-tell-whats-changed/ Share on other sites More sharing options...
dmikester1 Posted November 8, 2010 Share Posted November 8, 2010 Use the _POST values to test for equality to the current value in the database. Mike Link to comment https://forums.phpfreaks.com/topic/218144-how-to-tell-whats-changed/#findComment-1131987 Share on other sites More sharing options...
mike12255 Posted November 8, 2010 Author Share Posted November 8, 2010 do I have to go through each of the field manually or can you think of a faster way? Link to comment https://forums.phpfreaks.com/topic/218144-how-to-tell-whats-changed/#findComment-1131990 Share on other sites More sharing options...
dmikester1 Posted November 8, 2010 Share Posted November 8, 2010 If you let the default value for the select box be blank, I don't think that will come through on the POST values. I could be wrong about that, someone else could clarify that. Mike Link to comment https://forums.phpfreaks.com/topic/218144-how-to-tell-whats-changed/#findComment-1131992 Share on other sites More sharing options...
fortnox007 Posted November 9, 2010 Share Posted November 9, 2010 If you let the default value for the select box be blank, I don't think that will come through on the POST values. I could be wrong about that, someone else could clarify that. Mike I am pretty sure if you leave a value empty the $_POST var will still be set. edit yep vars are set: for illustration purposes: ?> <form action="" method="post"> <input type="text" name="bla" /> <input type="text" name="bla2" /> <input type="text" name="bla3" /> <input type="text" name="bla4" /> <input type="submit" name="submit" value="submit" /> </form> <?php print_r($_POST); // oprints: Array ( [bla] => [bla2] => [bla3] => [bla4] => [submit] => submit ) ?> Link to comment https://forums.phpfreaks.com/topic/218144-how-to-tell-whats-changed/#findComment-1132020 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.