logo-dw

Go Back   Dreamweaver Club Forums > Dreamweaver forums > Video Tutorials
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 02-11-2008, 01:22 AM   #1
smitho
 
Join Date: Dec 2007
Posts: 149
Default A Beginners Guide - Part11 refresh update table.

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.

PHP Code:
}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).

PHP Code:
}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 is offline   Reply With Quote
Old 02-11-2008, 01:35 AM   #2
smitho
 
Join Date: Dec 2007
Posts: 149
Default

I thought about this after but if you wanted to use the

PHP Code:
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.

HTML Code:
<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.
smitho is offline   Reply With Quote
Old 02-11-2008, 07:04 AM   #3
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

you could just move the SELECT statement above the UPDATE statement!

http://www.dreamweaverclub.com/forum...ighlight=medal
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:20 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com