How to page refreshing with previous submit value? |
Post Reply |
Author | |
djju1029
Senior Member Joined: Aug 02 2016 Location: the US Status: Offline Points: 126 |
Post Options
Thanks(0)
Posted: Oct 03 2016 at 3:35pm |
Helloe OE!
I am struggling to solve my issue on the web-app that are: 1. DB value is loaded on the page1 by submitted form value as following: //illu_laser_info_read.php <?php $id = array(); $id[0] = isset($_POST['WE1f81c75b9d']) ? $_POST['WE1f81c75b9d'] : ''; $id[1] = isset($_POST['WE13304d9158']) ? $_POST['WE13304d9158'] : ''; $id[2] = isset($_POST['WEa7232c35f7']) ? $_POST['WEa7232c35f7'] : ''; $id[3] = isset($_POST['WEcfed647dcc']) ? $_POST['WEcfed647dcc'] : ''; $id[4] = isset($_POST['WEb629737043']) ? $_POST['WEb629737043'] : ''; $id[5] = isset($_POST['WE1d8e4c1fe8']) ? $_POST['WE1d8e4c1fe8'] : ''; $id[6] = isset($_POST['WEd30ef1febb']) ? $_POST['WEd30ef1febb'] : ''; $id[7] = isset($_POST['WEca43243bf8']) ? $_POST['WEca43243bf8'] : ''; $id[8] = isset($_POST['WEb345d4674c']) ? $_POST['WEb345d4674c'] : ''; $id[9] = isset($_POST['WE25fefc8ec6']) ? $_POST['WE25fefc8ec6'] : ''; $id[10] = isset($_POST['WEda5919d59d']) ? $_POST['WEda5919d59d'] : ''; $id[11] = isset($_POST['WE7257f1328d']) ? $_POST['WE7257f1328d'] : ''; $key = array_search(TRUE, $id); $db = new PDO('sqlite:../Data/Local_previs_DB/illu.db'); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); if (is_bool($key) === FALSE) { // false when there is no system. if ($id[$key] !== "") { // false when sys_id is NULL $stmt = $db->prepare("SELECT * FROM illu_laser_stat WHERE sys_id='$id[$key]'"); $stmt->execute(); $read = $stmt->fetchAll(PDO::FETCH_ASSOC); } } else { $message = "No System!!!"; echo "<script type='text/javascript'>alert('$message');</script>"; } ?> //end This illu_laser_info_read.php is included on the Summary_laser_info.php. // the start of Summary_laser_info.php <?php require_once "Summary_laser_info(var).php"; include_once "../WEFiles/Server/DB/OEDB.php"; ?><?php include "illu_laser_info_read.php"; ?> <!DOCTYPE HTML> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> //...ellipsis and selected DB is displayed by jquery in Summary_laser_info.php at the end of body // the end of body of Summary_laser_info.php </div><script type="text/javascript"> $(function() { // write DB value on text input field WEc93bb51081 $('#WE562ca74f06 input').val("<?php echo $read[0]['sys_id']; ?>"); $('#WE24cc375ec5 input').val("<?php echo $read[0]['laser_temp_range']; ?>"); $('#WE77ece8c998 input').val("<?php echo $read[0]['laser_temp_tol']; ?>"); $('#WE3140f51f59 input').val("<?php echo $read[0]['out_lumen']; ?>"); $('#WE1762b3205b input').val("<?php echo $read[0]['max_mod_out_pwr']; ?>"); $('#WEba2a2fb72f input').val("<?php echo $read[0]['LD_const_pwr_max_ovrdrv']; ?>"); $('#WE99e87a03fa input').val("<?php echo $read[0]['optime_af_reboot']; ?>"); $('#WEe9928424c5 input').val("<?php echo $read[0]['LD_WL_r1']; ?>"); $('#WEbfaa61d9f6 input').val("<?php echo $read[0]['LD_WL_g1']; ?>"); $('#WE38a929cc38 input').val("<?php echo $read[0]['LD_WL_b1']; ?>"); $('#WE52c970de2c input').val("<?php echo $read[0]['LD_WL_r2']; ?>"); $('#WE70b54b2c91 input').val("<?php echo $read[0]['LD_WL_g2']; ?>"); $('#WE413301cee9 input').val("<?php echo $read[0]['LD_WL_b2']; ?>"); $('#WE99594ffc32 input').val("<?php echo $read[0]['setpt_r1']; ?>"); $('#WEcd21dff3c6 input').val("<?php echo $read[0]['setpt_g1']; ?>"); $('#WEb31ff62eab input').val("<?php echo $read[0]['setpt_b1']; ?>"); $('#WEb5a5d3ec4c input').val("<?php echo $read[0]['setpt_r2']; ?>"); $('#WE78c9b18145 input').val("<?php echo $read[0]['setpt_g2']; ?>"); $('#WE27dc381eff input').val("<?php echo $read[0]['setpt_b2']; ?>"); // select DB value on drop-down list field $('#WEd8e6c9ba03 select').val("<?php echo $read[0]['despec_sys_a']; ?>"); $('#WE2e71bd5b59 select').val("<?php echo $read[0]['despec_sys_b']; ?>"); }); </script> </body> </html> //end of file And when update button is clicked after changing some values, "illu_laser_stat_update.php" is executed such as //illu_laser_stat_update.php <?php //registerng by form $laser_stat_data = array(); $laser_stat_data[0] = $_POST['WE562ca74f06']; // sys_id $laser_stat_data[1] = $_POST['WE24cc375ec5']; // laser_temp_range $laser_stat_data[2] = $_POST['WE77ece8c998']; // laser_temp_tol $laser_stat_data[3] = $_POST['WEd8e6c9ba03']; // despec_sys_a $laser_stat_data[4] = $_POST['WE2e71bd5b59']; // despec_sys_b $laser_stat_data[5] = $_POST['WE3140f51f59']; // out_lumen $laser_stat_data[6] = $_POST['WE1762b3205b']; // max_mod_out_pwr $laser_stat_data[7] = $_POST['WEba2a2fb72f']; // LD_const_pwr_max_ovrdrv $laser_stat_data[8] = $_POST['WE99e87a03fa']; // optime_af_reboot $laser_stat_data[9] = $_POST['WEe9928424c5']; // LD_WL_r1 $laser_stat_data[10] = $_POST['WEbfaa61d9f6'];// LD_WL_g1 $laser_stat_data[11] = $_POST['WE38a929cc38'];// LD_WL_b1 $laser_stat_data[12] = $_POST['WE52c970de2c'];// LD_WL_r2 $laser_stat_data[13] = $_POST['WE70b54b2c91'];// LD_WL_g2 $laser_stat_data[14] = $_POST['WE413301cee9'];// LD_WL_b2 $laser_stat_data[15] = $_POST['WE99594ffc32'];// setpt_r1 $laser_stat_data[16] = $_POST['WEcd21dff3c6'];// setpt_g1 $laser_stat_data[17] = $_POST['WEb31ff62eab'];// setpt_b1 $laser_stat_data[18] = $_POST['WEb5a5d3ec4c'];// setpt_r2 $laser_stat_data[19] = $_POST['WE78c9b18145'];// setpt_g2 $laser_stat_data[20] = $_POST['WE27dc381eff'];// setpt_b2 //open DB $db = new PDO('sqlite:../Data/Local_previs_DB/illu.db'); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //read DB $readstmt = $db->prepare("SELECT * FROM illu_laser_stat WHERE sys_id = '$laser_stat_data[0]'"); $readstmt->execute(); $upread = $readstmt->fetchAll(PDO::FETCH_NUM); //update DB if ($laser_stat_data !== $upread[0]) { // if there is any change, then update whole row $updatestmt = $db->prepare("UPDATE illu_laser_stat SET laser_temp_range =(:value1), laser_temp_tol =(:value2), despec_sys_a =(:value3), despec_sys_b =(:value4), out_lumen =(:value5), max_mod_out_pwr =(:value6), LD_const_pwr_max_ovrdrv =(:value7), optime_af_reboot =(:value8), LD_WL_r1 =(:value9), LD_WL_g1 =(:value10), LD_WL_b1 =(:value11), LD_WL_r2 =(:value12), LD_WL_g2 =(:value13), LD_WL_b2 =(:value14), setpt_r1 =(:value15), setpt_g1 =(:value16), setpt_b1 =(:value17), setpt_r2 =(:value18), setpt_g2 =(:value19), setpt_b2 =(:value20) WHERE sys_id='$laser_stat_data[0]'"); $updatestmt->bindParam(':value1', $laser_stat_data[1] ); $updatestmt->bindParam(':value2', $laser_stat_data[2] ); $updatestmt->bindParam(':value3', $laser_stat_data[3] ); $updatestmt->bindParam(':value4', $laser_stat_data[4] ); $updatestmt->bindParam(':value5', $laser_stat_data[5] ); $updatestmt->bindParam(':value6', $laser_stat_data[6] ); $updatestmt->bindParam(':value7', $laser_stat_data[7] ); $updatestmt->bindParam(':value8', $laser_stat_data[8] ); $updatestmt->bindParam(':value9', $laser_stat_data[9] ); $updatestmt->bindParam(':value10', $laser_stat_data[10]); $updatestmt->bindParam(':value11', $laser_stat_data[11]); $updatestmt->bindParam(':value12', $laser_stat_data[12]); $updatestmt->bindParam(':value13', $laser_stat_data[13]); $updatestmt->bindParam(':value14', $laser_stat_data[14]); $updatestmt->bindParam(':value15', $laser_stat_data[15]); $updatestmt->bindParam(':value16', $laser_stat_data[16]); $updatestmt->bindParam(':value17', $laser_stat_data[17]); $updatestmt->bindParam(':value18', $laser_stat_data[18]); $updatestmt->bindParam(':value19', $laser_stat_data[19]); $updatestmt->bindParam(':value20', $laser_stat_data[20]); $updatestmt->execute(); } header('Location: ./Summary_laser_info.php'); // refreshing page after reading DB ?> //end But, reloading "./Summary_laser_info.php" page cannot load previous sumbitted form value from previous page. For instance, if Summary_laser_info is redirected from DB value, sys_id = 1 I want to reload the page after updating with previous sys_id value = 1. But, header('Location: ./Summary_laser_info.php'); cannot refresh the page with previous sys_id. I have been struggling this issue from last Monday up to now...a week......but I could not. I tried to auto-submit by Javascript on "illu_laser_stat_update.php" but it didn't work. Could you help me out from this issue? I really appreciate your expertise help in advance. DJ Joo Edited by djju1029 - Oct 03 2016 at 3:36pm |
|
Dmit OE
Admin Group Joined: May 31 2012 Status: Offline Points: 5283 |
Post Options
Thanks(1)
|
Hi,
You shoudl transfer the data you want, via URL parameters ($_GET) or session ($_SESSION), or re-read them from DB if they are stored there. I can't understand how your system works exactly so I can't say more precisely. Try to describe, without posting the code, the "logic" - what page opens first, what user does, when and what data are written to DB etc. |
|
djju1029
Senior Member Joined: Aug 02 2016 Location: the US Status: Offline Points: 126 |
Post Options
Thanks(0)
|
Oh! I see, the logic instead of code.
the page structure is index.php // 12 systems status are displayed in one page \Summary\Summary_laser_info.php // 20 laser parameters of one system which is selected by user are displayed \Summary\illu_laser_info_read.php // read DB, illu_laser_stat \Summary\illu_laser_stat_update.php // update DB, illu_laser_stat the DB table structure is illu.db \illu_summary // 12 systems status stored \illu_laser_stat // 20 system parameters of 1 system are stored The logic is 1. After log-in, the index page shows 12 systems status according current DB table, illu_summary 2. The user click the one of 12 icons of laser info to check the system parameters. (for example, we assume the user click the System 1 icon) 3. The sys_id = 0, which is DB value of system id of 'illu_summary' table is submitted by FORM OE element to 'Summary_laser_info.php' Form Configuration Destination URL: Summary/Summary_laser_info.php Method: Post Target: Same window or tab Encryption: text/plain Submit button: Icon_system_laser Form Element to Submit: system_id_01(WE1f81c75b9d) // it contains sys_id value = 0 4. 'illu_laser_info_read.php' is included on top of 'Summary_laser_info.php' it reads row where sys_id = 0, 5. Form text element values of 'System_laser_info.php' are displayed by jquery function script at the end of 'illu_laser_info_read.php' 6. 'illu_laser_info_read.php' has update icon to update changed text in form elements to DB. 7. The user would change some value of elements and click the UPDATE icon, then the form is submitted such as Form Configuration Destination URL: Summary/illu_laser_stat_update.php Method: Post Target: Same window or tab Encryption: text/plain Submit button: ApplyNow (WE2aa738adca) Form Element to Submit: 21 TEXT INPUT FIELDs I have checked that the DB is updated successfully with user-changing value. However, I want to refresh the page after updating with with user-changing value but if I refresh the 'Summary_laser_info.php' at the end of 'illu_laser_stat_update.php', it cannot show sys_id 0's parameters because 'illu_laser_info_read.php' has no submitted form value. In conclusion, I want to refresh the page after DB updating with previous submitted form value. Edited by djju1029 - Oct 03 2016 at 5:30pm |
|
djju1029
Senior Member Joined: Aug 02 2016 Location: the US Status: Offline Points: 126 |
Post Options
Thanks(0)
|
Or, I want to know how to display the updated value from DB table without refreshing the page.
|
|
Dmit OE
Admin Group Joined: May 31 2012 Status: Offline Points: 5283 |
Post Options
Thanks(1)
|
There's someting I don't understand. When you "update", you are writing the data to DB (and you say it works). So, basically, you just need to show the values coming from DB after the update. Is it just sys_id that you need to know? In this case, in your header("Location...."), add it to the URL parameter (you need to set correctly the $sysID variable):
$sysID=....; // depending on how you get it at this moment header("Location: ./Summary_laser_info.php?sys_id=$sysID"); Now, what confusesw me is your code to get sys ID in the first part of your code: $key = array_search(TRUE, $id); .... "SELECT * FROM illu_laser_stat WHERE sys_id='$id[$key]'" this makes perfecly zero sense. You search the value TRUE in array then you get this value again... In the second part it seems more logical: SELECT * FROM illu_laser_stat WHERE sys_id = '$laser_stat_data[0]'" Please re-analyse your code, with clear view on what it should do and why, I think you will find all the missing pieces. |
|
Dmit OE
Admin Group Joined: May 31 2012 Status: Offline Points: 5283 |
Post Options
Thanks(1)
|
P.S. To update without refreshing, you need to use Ajax. Find some examples of using Ajax with jQuery that resemble your situation, it's not very complex if you find good ones.
|
|
djju1029
Senior Member Joined: Aug 02 2016 Location: the US Status: Offline Points: 126 |
Post Options
Thanks(0)
|
Thank you for your great help. I resolved the issue!
|
|
Dmit OE
Admin Group Joined: May 31 2012 Status: Offline Points: 5283 |
Post Options
Thanks(1)
|
Perfect!
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |