Jump to content

Temporary working while loop selection


CloudBreaker

Recommended Posts

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>
Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.