CloudBreaker Posted August 6, 2015 Share Posted August 6, 2015 So I got the previous selection issues worked out and the selected user is inserted into the database. However, if I go back and edit another field...say the Date....then the name in "The Final Answer by:" field disappears and I have to go back and edit the form and select the name again. I echoed the selected name on line 177, hoping the name would stay, but it runs the rest of the script and since nothing is selected when another field is being edited, the name is taking out unless I choose the name again. How could I change the functionality to keep the name if another field has to be edited and still be able to change the name if it needs to be changed? thanks CB <?php //Gather Information $sql = "SELECT * FROM user_project WHERE project_id='$project_id'"; $result = mysqli_query($conn,$sql) or die (mysql_error()); if ($_SERVER["REQUEST_METHOD"] == "POST") { // if you submitted the form if(isset($_POST['submit_data'])){ $answered_by = $_POST["first_name"]; } $sql = "UPDATE `hsa_project_hub`.`rfis` SET `answered_by` = '$answered_by', `time` = NOW() WHERE `rfis`.`no` = '$id';"; if (mysqli_query($conn, $sql)) { echo "Name entered successfully"; } else { echo "Error: " . $sql . "<br>" . mysqli_error($conn); } } ?> <p>Final Answer by: <select name="first_name" > <option value="" > <?php echo $answered_by;?></option> <!-- Loop For Fetch Result --> <?php while($row = mysqli_fetch_array($result) ) : ?> <option><?php echo($row['first_name']) , ' ', ($row['last_name']);?></option> <?php endwhile; ?> <!-- End Loop for Fetch Result --> </select> </p> <input type="file" name="files[]" multiple="" /> <br class="clear" /><br> <center><input type="submit" name="submit_data" id="submit_data" value="Modify RFI" /></center> </form> Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted August 7, 2015 Share Posted August 7, 2015 do a query for the data to populate the form if the query returned no results would be an insert if the query returned results and it populated the post fields, do the update on the submit It's up to you if want to just update all values or do checks if anything is different and dynamically build the query for the update. Alternately you can do something more advanced and do ajax on each form input, something like a live edit Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.