PDA

View Full Version : A Beginners Guide - Part11 refresh update table.


smitho
02-11-2008, 01:22 AM
I've made my way through the tuts and in the last one davidj points out a problem where when you hit the submit button and apply the change you've made, the change occurs to the table and database but not in the input table which keeps the original number/value. This could cause problems if the user accidentally hits the submit button again resulting in the original number/value being put in again.


Now I don't know if this is the best way to do it but you could add a header("location:....");


This example with display the value you just typed in.

}elseif($submit && $update_id){

/////////////////////////////////////
$query = sprintf("UPDATE table1 SET field2='$data2', field3='$data3', field4='$data4' WHERE field1_id='$update_id'");
$result = @mysql_query($query);
header("Location: dwc.php?upd=$update_id");
/////////////////////////////////////

}This example will apply the change and clear the input fields (my preference).

}elseif($submit && $update_id){

/////////////////////////////////////
$query = sprintf("UPDATE table1 SET field2='$data2', field3='$data3', field4='$data4' WHERE field1_id='$update_id'");
$result = @mysql_query($query);
header("Location: dwc.php");
/////////////////////////////////////

}

smitho
02-11-2008, 01:35 AM
I thought about this after but if you wanted to use the

header("Location: dwc.php?upd=$update_id");option so that you can see what you've altered but them want to clear the form you could try this. Add a clear button next to the submit.

<input type="button" name="submit3" value="Clear" onclick="document.location.href='dwc.php'"/>
<input type="reset" name="submit2" value="Reset" />
<input type="submit" name="Submit" value="Submit" />
<input name="submit" type="hidden" id="submit" value="1" />
<input name="update_id" type="hidden" id="update_id" value="<?php echo $rowUpdate['field1_id'];?>" />Again not sure if this is the best way but it works.

davidj
02-11-2008, 07:04 AM
you could just move the SELECT statement above the UPDATE statement!

http://www.dreamweaverclub.com/forum/showthread.php?t=25457&page=2&highlight=medal