3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(E_ALL); // Connect to the DB //$link = mysqli_connect("localhost", "firstcor_frstuse", "{gV43i0VX@U}") or die("Error " . mysqli_error($link)); include ('connect.php'); //$ID=$_GET["ID"]; $dep_rate_cat=$_GET["CAT"]; echo $dep_rate_cat; // store in the DB if(!empty($_POST['ok'])) { // first delete the records marked for deletion. Why? Because we don't want to process them in the code below if( !empty($_POST['delete_IDs']) and is_array($_POST['delete_IDs'])) { // you can optimize below into a single query, but let's keep it simple and clear for now: foreach($_POST['delete_IDs'] as $ID) { $sql = "DELETE FROM tblRates_balance WHERE ID=$ID"; $link->query($sql); } } // now, to edit the existing data, we have to select all the records in a variable. $sql="SELECT * FROM tblRates_balance ORDER BY ID where dep_rate_cat=$dep_rate_cat"; $result = $link->query($sql); // now edit them while($tblRates_balance = mysqli_fetch_array($result)) { // remember how we constructed the field names above? This was with the IDea to access the values easy now $sql = "UPDATE tblRates_balance SET dep_rate_cat=$dep_rate_cat, Min_Balance='".$_POST['Min_Balance'.$tblRates_balance['ID']]."', Interest_Rate='".$_POST['Interest_rate'.$tblRates_balance['ID']]."', Apy='".$_POST['Apy'.$tblRates_balance['ID']]."', sub_order='".$_POST['sub_order'.$tblRates_balance['ID']]."' WHERE ID='$tblRates_balance[ID]'"; $link->query($sql); } // (feel free to optimize this so query is executed only when a product is actually changed) // adding new if(!empty($_POST['Min_Balance'])) { foreach($_POST['Min_Balance'] as $cnt => $Min_Balance) { $sql = "INSERT INTO tblRates_balance (dep_rate_cat, Min_Balance, Interst_Rate, APY,sub_order) VALUES ('$dep_rate_cat','$Min_Balance', '".$_POST['Interest_rate'][$cnt]."', '".$_POST['APY'][$cnt]."','".$_POST['sub_order'][$cnt]." );"; $link->query($sql); } } } // select existing products here $sql="SELECT * FROM tblRates_balance ORDER BY dep_rate_cat"; $result = $link->query($sql); ?> <html> <head> <title>Simple example of dynamically adding rows with jQuery</title> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.3.js"></script> </head> <body> <div style="width:90%;margin:auto;"> <h1>Simple example of dynamically adding rows with jQuery </h1> <form action="<? echo htmlentities($_SERVER['PHP_SELF']); ?>" method="POST"> <div ID="itemRows"> Minimum Balance: <input type="text" name="Minimum_Balance" size="30" /> Interest Rate: <input type="text" name="Interest_Rate" /> APY: <input type="text" name="APY" /> Order: <input type="text" name="sub_order" size="2"/> <input onClick="addRow(this.form);" type="button" value="Add row" /> (This row will not be saved unless you click on "Add row" first) <?php // let's assume you have the product data from the DB in variable called $tblRates_balances while($tblRates_balance = mysqli_fetch_array($result)): ?> <p ID="oldRow<?=$tblRates_balance['ID']?>"> <input type="text" name="dep_rate_cat<?=$tblRates_balance['dep_rate_cat']?>" size="4" value="<?=$tblRates_balance['dep_rate_cat']?> Minimum Balance: <input type="text" name="Min_Balance<?=$tblRates_balance['Min_Balance']?>" size="4" value="<?=$tblRates_balance['Min_Balance']?>" /> Interest Rate: <input type="text" name="Interest_rate<?=$tblRates_balance['Interest_Rate']?>" value="<?=$tblRates_balance['Interest_Rate']?>" /> APY: <input type="text" name="Apy<?=$tblRates_balance['Apy']?>" value="<?=$tblRates_balance['Apy']?>" /> Order: <input type="text" name="sub_order<?=$tblRates_balance['sub_order']?>" value="<?=$tblRates_balance['sub_order']?>" /> <input type="checkbox" name="delete_IDs[]" value="<?=$tblRates_balance['ID']?>"> Mark to delete</p> <?php endwhile;?> </div> <p><input type="submit" name="ok" value="Save Changes"></p> </form> </div> <script type="text/javascript"> var rowNum = 0; function addRow(frm) { rowNum ++; var row = '<p ID="rowNum'+rowNum+'">Minimum Balance : <input type="text" name="Min_balance[]" size="4" value="'+frm.add_Min_Balance.value+'"> Interest Rate: <input type="text" name="Interest_Rate[]" value="'+frm.add_Interest_Rate.value+'"> APY: <input type="text" name="Apy[]" value="'+frm.add_Apy.value+'"> Order: <input type="text" name="sub_order[]" value="'+frm.add_sub_order.value+'"> <input type="button" value="Remove" onclick="removeRow('+rowNum+');"></p>'; jQuery('#itemRows').append(row); frm.add_Min_Balance.value = ''; frm.add_Interest_Rate.value = ''; frm.add_Apy.value = ''; frm.add_sub_order.value = ''; } function removeRow(rnum) { jQuery('#rowNum'+rnum).remove(); } </script> </body> </html>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 116
Branch analysis from position: 12
2 jumps found. (Code = 46) Position 1 = 16, Position 2 = 20
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 33
Branch analysis from position: 21
2 jumps found. (Code = 77) Position 1 = 24, Position 2 = 32
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 32
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 76
Branch analysis from position: 76
2 jumps found. (Code = 44) Position 1 = 81, Position 2 = 41
Branch analysis from position: 81
2 jumps found. (Code = 43) Position 1 = 85, Position 2 = 116
Branch analysis from position: 85
2 jumps found. (Code = 77) Position 1 = 88, Position 2 = 115
Branch analysis from position: 88
2 jumps found. (Code = 78) Position 1 = 89, Position 2 = 115
Branch analysis from position: 89
1 jumps found. (Code = 42) Position 1 = 88
Branch analysis from position: 88
Branch analysis from position: 115
1 jumps found. (Code = 42) Position 1 = 167
Branch analysis from position: 167
2 jumps found. (Code = 44) Position 1 = 172, Position 2 = 130
Branch analysis from position: 172
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 130
2 jumps found. (Code = 44) Position 1 = 172, Position 2 = 130
Branch analysis from position: 172
Branch analysis from position: 130
Branch analysis from position: 115
Branch analysis from position: 116
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 81, Position 2 = 41
Branch analysis from position: 81
Branch analysis from position: 41
Branch analysis from position: 32
Branch analysis from position: 33
Branch analysis from position: 20
Branch analysis from position: 116
filename:       /in/aXTKX
function name:  (null)
number of ops:  174
compiled vars:  !0 = $dep_rate_cat, !1 = $ID, !2 = $sql, !3 = $link, !4 = $result, !5 = $tblRates_balance, !6 = $Min_Balance, !7 = $cnt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 32767
          2        DO_ICALL                                                 
    5     3        INCLUDE_OR_EVAL                                          'connect.php', INCLUDE
    7     4        FETCH_R                      global              ~10     '_GET'
          5        FETCH_DIM_R                                      ~11     ~10, 'CAT'
          6        ASSIGN                                                   !0, ~11
    9     7        ECHO                                                     !0
   11     8        FETCH_IS                                         ~13     '_POST'
          9        ISSET_ISEMPTY_DIM_OBJ                         1  ~14     ~13, 'ok'
         10        BOOL_NOT                                         ~15     ~14
         11      > JMPZ                                                     ~15, ->116
   13    12    >   FETCH_IS                                         ~16     '_POST'
         13        ISSET_ISEMPTY_DIM_OBJ                         1  ~17     ~16, 'delete_IDs'
         14        BOOL_NOT                                         ~18     ~17
         15      > JMPZ_EX                                          ~18     ~18, ->20
         16    >   FETCH_R                      global              ~19     '_POST'
         17        FETCH_DIM_R                                      ~20     ~19, 'delete_IDs'
         18        TYPE_CHECK                                  128  ~21     ~20
         19        BOOL                                             ~18     ~21
         20    > > JMPZ                                                     ~18, ->33
   15    21    >   FETCH_R                      global              ~22     '_POST'
         22        FETCH_DIM_R                                      ~23     ~22, 'delete_IDs'
         23      > FE_RESET_R                                       $24     ~23, ->32
         24    > > FE_FETCH_R                                               $24, !1, ->32
   16    25    >   NOP                                                      
         26        FAST_CONCAT                                      ~25     'DELETE+FROM+tblRates_balance+WHERE+ID%3D', !1
         27        ASSIGN                                                   !2, ~25
   17    28        INIT_METHOD_CALL                                         !3, 'query'
         29        SEND_VAR_EX                                              !2
         30        DO_FCALL                                      0          
   15    31      > JMP                                                      ->24
         32    >   FE_FREE                                                  $24
   22    33    >   NOP                                                      
         34        FAST_CONCAT                                      ~28     'SELECT+%2A+FROM+tblRates_balance+ORDER+BY+ID+where+dep_rate_cat%3D', !0
         35        ASSIGN                                                   !2, ~28
   23    36        INIT_METHOD_CALL                                         !3, 'query'
         37        SEND_VAR_EX                                              !2
         38        DO_FCALL                                      0  $30     
         39        ASSIGN                                                   !4, $30
   26    40      > JMP                                                      ->76
   28    41    >   ROPE_INIT                                     3  ~33     'UPDATE+tblRates_balance+SET+dep_rate_cat%3D'
         42        ROPE_ADD                                      1  ~33     ~33, !0
         43        ROPE_END                                      2  ~32     ~33, '%2C+Min_Balance%3D%27'
         44        FETCH_DIM_R                                      ~36     !5, 'ID'
         45        CONCAT                                           ~37     'Min_Balance', ~36
         46        FETCH_R                      global              ~35     '_POST'
         47        FETCH_DIM_R                                      ~38     ~35, ~37
         48        CONCAT                                           ~39     ~32, ~38
         49        CONCAT                                           ~40     ~39, '%27%2C+Interest_Rate%3D%27'
         50        FETCH_DIM_R                                      ~42     !5, 'ID'
         51        CONCAT                                           ~43     'Interest_rate', ~42
         52        FETCH_R                      global              ~41     '_POST'
         53        FETCH_DIM_R                                      ~44     ~41, ~43
         54        CONCAT                                           ~45     ~40, ~44
         55        CONCAT                                           ~46     ~45, '%27%2C+Apy%3D%27'
         56        FETCH_DIM_R                                      ~48     !5, 'ID'
         57        CONCAT                                           ~49     'Apy', ~48
         58        FETCH_R                      global              ~47     '_POST'
         59        FETCH_DIM_R                                      ~50     ~47, ~49
         60        CONCAT                                           ~51     ~46, ~50
         61        CONCAT                                           ~52     ~51, '%27%2C+sub_order%3D%27'
         62        FETCH_DIM_R                                      ~54     !5, 'ID'
         63        CONCAT                                           ~55     'sub_order', ~54
         64        FETCH_R                      global              ~53     '_POST'
         65        FETCH_DIM_R                                      ~56     ~53, ~55
         66        CONCAT                                           ~57     ~52, ~56
         67        ROPE_INIT                                     3  ~60     '%27%0A%09%09WHERE+ID%3D%27'
   29    68        FETCH_DIM_R                                      ~58     !5, 'ID'
         69        ROPE_ADD                                      1  ~60     ~60, ~58
         70        ROPE_END                                      2  ~59     ~60, '%27'
         71        CONCAT                                           ~62     ~57, ~59
   28    72        ASSIGN                                                   !2, ~62
   31    73        INIT_METHOD_CALL                                         !3, 'query'
         74        SEND_VAR_EX                                              !2
         75        DO_FCALL                                      0          
   26    76    >   INIT_FCALL_BY_NAME                                       'mysqli_fetch_array'
         77        SEND_VAR_EX                                              !4
         78        DO_FCALL                                      0  $65     
         79        ASSIGN                                           ~66     !5, $65
         80      > JMPNZ                                                    ~66, ->41
   38    81    >   FETCH_IS                                         ~67     '_POST'
         82        ISSET_ISEMPTY_DIM_OBJ                         1  ~68     ~67, 'Min_Balance'
         83        BOOL_NOT                                         ~69     ~68
         84      > JMPZ                                                     ~69, ->116
   39    85    >   FETCH_R                      global              ~70     '_POST'
         86        FETCH_DIM_R                                      ~71     ~70, 'Min_Balance'
         87      > FE_RESET_R                                       $72     ~71, ->115
         88    > > FE_FETCH_R                                       ~73     $72, !6, ->115
         89    >   ASSIGN                                                   !7, ~73
   40    90        ROPE_INIT                                     5  ~76     'INSERT+INTO+tblRates_balance+%28dep_rate_cat%2C+Min_Balance%2C+Interst_Rate%2C+APY%2Csub_order%29+VALUES+%28%27'
         91        ROPE_ADD                                      1  ~76     ~76, !0
         92        ROPE_ADD                                      2  ~76     ~76, '%27%2C%27'
         93        ROPE_ADD                                      3  ~76     ~76, !6
         94        ROPE_END                                      4  ~75     ~76, '%27%2C+%27'
         95        FETCH_R                      global              ~79     '_POST'
         96        FETCH_DIM_R                                      ~80     ~79, 'Interest_rate'
         97        FETCH_DIM_R                                      ~81     ~80, !7
         98        CONCAT                                           ~82     ~75, ~81
         99        CONCAT                                           ~83     ~82, '%27%2C+%27'
        100        FETCH_R                      global              ~84     '_POST'
        101        FETCH_DIM_R                                      ~85     ~84, 'APY'
        102        FETCH_DIM_R                                      ~86     ~85, !7
        103        CONCAT                                           ~87     ~83, ~86
        104        CONCAT                                           ~88     ~87, '%27%2C%27'
        105        FETCH_R                      global              ~89     '_POST'
        106        FETCH_DIM_R                                      ~90     ~89, 'sub_order'
        107        FETCH_DIM_R                                      ~91     ~90, !7
        108        CONCAT                                           ~92     ~88, ~91
        109        CONCAT                                           ~93     ~92, '+%29%3B'
        110        ASSIGN                                                   !2, ~93
   41   111        INIT_METHOD_CALL                                         !3, 'query'
        112        SEND_VAR_EX                                              !2
        113        DO_FCALL                                      0          
   39   114      > JMP                                                      ->88
        115    >   FE_FREE                                                  $72
   47   116    >   ASSIGN                                                   !2, 'SELECT+%2A+FROM+tblRates_balance+ORDER+BY+dep_rate_cat'
   48   117        INIT_METHOD_CALL                                         !3, 'query'
        118        SEND_VAR_EX                                              !2
        119        DO_FCALL                                      0  $97     
        120        ASSIGN                                                   !4, $97
   50   121        ECHO                                                     '%0A%3Chtml%3E%0A%3Chead%3E%0A%09%3Ctitle%3ESimple+example+of+dynamically+adding+rows+with+jQuery%3C%2Ftitle%3E%0A%09%3Cscript+type%3D%22text%2Fjavascript%22+src%3D%22http%3A%2F%2Fajax.aspnetcdn.com%2Fajax%2FjQuery%2Fjquery-2.0.3.js%22%3E%3C%2Fscript%3E%0A%3C%2Fhead%3E%0A%0A%3Cbody%3E%0A%0A%3Cdiv+style%3D%22width%3A90%25%3Bmargin%3Aauto%3B%22%3E%0A%09%3Ch1%3ESimple+example+of+dynamically+adding+rows+with+jQuery+%3C%2Fh1%3E%0A%09%0A%3Cform+action%3D%22'
   62   122        INIT_FCALL                                               'htmlentities'
        123        FETCH_R                      global              ~99     '_SERVER'
        124        FETCH_DIM_R                                      ~100    ~99, 'PHP_SELF'
        125        SEND_VAL                                                 ~100
        126        DO_ICALL                                         $101    
        127        ECHO                                                     $101
        128        ECHO                                                     '%22+method%3D%22POST%22%3E%0A%09%3Cdiv+ID%3D%22itemRows%22%3E%0A%09%0A%09Minimum+Balance%3A+%3Cinput+type%3D%22text%22+name%3D%22Minimum_Balance%22+size%3D%2230%22+%2F%3E+%0A++++Interest+Rate%3A+%3Cinput+type%3D%22text%22+name%3D%22Interest_Rate%22+%2F%3E+%0A++++APY%3A+%3Cinput+type%3D%22text%22+name%3D%22APY%22+%2F%3E+%0A+++++Order%3A+%3Cinput+type%3D%22text%22+name%3D%22sub_order%22+size%3D%222%22%2F%3E+%0A++++%0A++++%0A++++%0A++++%3Cinput+onClick%3D%22addRow%28this.form%29%3B%22+type%3D%22button%22+value%3D%22Add+row%22+%2F%3E+%28This+row+will+not+be+saved+unless+you+click+on+%22Add+row%22+first%29%0A%0A%09'
   77   129      > JMP                                                      ->167
   78   130    >   ECHO                                                     '%09%09%3Cp+ID%3D%22oldRow'
        131        FETCH_DIM_R                                      ~102    !5, 'ID'
        132        ECHO                                                     ~102
        133        ECHO                                                     '%22%3E%0A++++++++%0A++++++++%3Cinput+type%3D%22text%22+name%3D%22dep_rate_cat'
   80   134        FETCH_DIM_R                                      ~103    !5, 'dep_rate_cat'
        135        ECHO                                                     ~103
        136        ECHO                                                     '%22+size%3D%224%22+value%3D%22'
        137        FETCH_DIM_R                                      ~104    !5, 'dep_rate_cat'
        138        ECHO                                                     ~104
   81   139        ECHO                                                     '++++++++Minimum+Balance%3A+%3Cinput+type%3D%22text%22+name%3D%22Min_Balance'
        140        FETCH_DIM_R                                      ~105    !5, 'Min_Balance'
        141        ECHO                                                     ~105
        142        ECHO                                                     '%22+size%3D%224%22+value%3D%22'
        143        FETCH_DIM_R                                      ~106    !5, 'Min_Balance'
        144        ECHO                                                     ~106
        145        ECHO                                                     '%22+%2F%3E%0A+++++++++Interest+Rate%3A+%3Cinput+type%3D%22text%22+name%3D%22Interest_rate'
   82   146        FETCH_DIM_R                                      ~107    !5, 'Interest_Rate'
        147        ECHO                                                     ~107
        148        ECHO                                                     '%22+value%3D%22'
        149        FETCH_DIM_R                                      ~108    !5, 'Interest_Rate'
        150        ECHO                                                     ~108
        151        ECHO                                                     '%22+%2F%3E+%0A++++++++%0A+++++++++APY%3A+%3Cinput+type%3D%22text%22+name%3D%22Apy'
   84   152        FETCH_DIM_R                                      ~109    !5, 'Apy'
        153        ECHO                                                     ~109
        154        ECHO                                                     '%22+value%3D%22'
        155        FETCH_DIM_R                                      ~110    !5, 'Apy'
        156        ECHO                                                     ~110
        157        ECHO                                                     '%22+%2F%3E%0A++++++++++Order%3A+%3Cinput+type%3D%22text%22+name%3D%22sub_order'
   85   158        FETCH_DIM_R                                      ~111    !5, 'sub_order'
        159        ECHO                                                     ~111
        160        ECHO                                                     '%22+value%3D%22'
        161        FETCH_DIM_R                                      ~112    !5, 'sub_order'
        162        ECHO                                                     ~112
        163        ECHO                                                     '%22+%2F%3E%0A+++++++++%3Cinput+type%3D%22checkbox%22+name%3D%22delete_IDs%5B%5D%22+value%3D%22'
   86   164        FETCH_DIM_R                                      ~113    !5, 'ID'
        165        ECHO                                                     ~113
        166        ECHO                                                     '%22%3E+Mark+to+delete%3C%2Fp%3E%0A++++++++%0A%0A%09'
   77   167    >   INIT_FCALL_BY_NAME                                       'mysqli_fetch_array'
        168        SEND_VAR_EX                                              !4
        169        DO_FCALL                                      0  $114    
        170        ASSIGN                                           ~115    !5, $114
        171      > JMPNZ                                                    ~115, ->130
   90   172    >   ECHO                                                     '%09%0A%09%3C%2Fdiv%3E%0A%09%0A%09%3Cp%3E%3Cinput+type%3D%22submit%22+name%3D%22ok%22+value%3D%22Save+Changes%22%3E%3C%2Fp%3E%0A%09%3C%2Fform%3E%0A%3C%2Fdiv%3E%0A%0A%3Cscript+type%3D%22text%2Fjavascript%22%3E%0Avar+rowNum+%3D+0%3B%0Afunction+addRow%28frm%29+%7B%0A%09rowNum+%2B%2B%3B%0A%09var+row+%3D+%27%3Cp+ID%3D%22rowNum%27%2BrowNum%2B%27%22%3EMinimum+Balance+%3A+%3Cinput+type%3D%22text%22+name%3D%22Min_balance%5B%5D%22+size%3D%224%22+value%3D%22%27%2Bfrm.add_Min_Balance.value%2B%27%22%3E+%0A%09Interest+Rate%3A+%3Cinput+type%3D%22text%22+name%3D%22Interest_Rate%5B%5D%22+value%3D%22%27%2Bfrm.add_Interest_Rate.value%2B%27%22%3E+%0A%09APY%3A+%3Cinput+type%3D%22text%22+name%3D%22Apy%5B%5D%22+value%3D%22%27%2Bfrm.add_Apy.value%2B%27%22%3E%0A%09Order%3A+%3Cinput+type%3D%22text%22+name%3D%22sub_order%5B%5D%22+value%3D%22%27%2Bfrm.add_sub_order.value%2B%27%22%3E%0A%09%3Cinput+type%3D%22button%22+value%3D%22Remove%22+onclick%3D%22removeRow%28%27%2BrowNum%2B%27%29%3B%22%3E%3C%2Fp%3E%27%3B%0A%09jQuery%28%27%23itemRows%27%29.append%28row%29%3B%0A%09frm.add_Min_Balance.value+%3D+%27%27%3B%0A%09frm.add_Interest_Rate.value+%3D+%27%27%3B%0A%09frm.add_Apy.value+%3D+%27%27%3B%0A%09frm.add_sub_order.value+%3D+%27%27%3B%0A%7D%0A%0A%0Afunction+removeRow%28rnum%29+%7B%0A%09jQuery%28%27%23rowNum%27%2Brnum%29.remove%28%29%3B%0A%7D%0A%3C%2Fscript%3E%0A%3C%2Fbody%3E%09%0A%3C%2Fhtml%3E'
  119   173      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.96 ms | 1416 KiB | 17 Q