Jump to content

How to tell whats changed.


mike12255

Recommended Posts

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

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 ) 
        ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.