We help IT Professionals succeed at work.
Get Started

Update form won't update

398 Views
Last Modified: 2012-08-14
<?php
session_start();

require ('header.html');
	
date_default_timezone_set('America/Los_Angeles');

if(isset($_SESSION['valid_user'])){
	echo '<div class="content"><div class="item">';
	require('dbc.php');
	connect_db();
	$query = "Select * FROM SitRepReport WHERE IncidentName = '{$_POST['IncidentName']}'";
		if($r = mysql_query($query)){
			while($row = mysql_fetch_array($r)){
				(variable declarations)
			}
		}
		if(isset($_POST['submit'])){
		
			$problem = FALSE;
	
			if(empty($_POST['A bunch of conditionals'])){
				$problem = TRUE;
				echo'<p><h2>Please go back you missed something!</h2></p>';
			}
		
			if(!$problem){
				$updtQuery = "UPDATE SitRepReport SET Values";
					if(@mysql_query($updtQuery)){
						echo'<div class = "item"><h1>REPORT UPDATED</h1><p>Your report has been updated.</p></div>';
		
					}else{
						echo"<div class = \"item\"><h1>MySQL Error</h1><div class = \"descr\">Error Generated</div><p>Could not submit report because: <b>".mysql_error()."</b>.  The query was $updtQuery.</p></div>";
					}	
			}
		}

	echo'<form>Form is populated by above declared variables using MySQL</form>';
	
	close_db();

}else{
	echo '<h1>YOU ARE NOT LOGGED IN!</h1>';
}
require ('footer.html');
?>

Open in new window

Greetings experts,

I have a reporting form which is stored the date enterd into a MySQL DB.  Once the user has input the data I have given them the option to change said data need be.

The update form is set up to load the previously entered data so the user only need to change the one or two items he/she wishes to change.  Once they click the update button the new data is sent to the DB.  All of which works fine.

The problem I am having is once the update button is clicked the data is being updated in the DB but the form refreshs back to the orinal data and I am afraid this will confuse my users.  They can see the form change if they manually click the refresh button but the too provides a warning about resending data which I fear will also confuse them.

Is there a way to stop this from occuring?  I have tried reload, redirect back to the same page.

I am a beginner in PHP so I don't know all the tricks.

I have included my abriviated code below.
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE