dragonfaster Posted April 25, 2017 Share Posted April 25, 2017 Hi,As the title said, i'm trying to update an SQL Server DB with php. From my code below, you can see that i call once a stored proc to get information who will be in a table. One of the row allow me (supposed to be)(the last row who is an input), to change an other one (row name GL). But with the button save, it seems like nothing change at all. I tried to make some log with console and i can see test1 and test2. So it seems like it can go throught but doesnt ajust anything. I really don't know anymore and i really need your help. Any ideas or help will be really really appreciate. More on that, i'm not sure if i do it well about sql injection... <?php if(isset($_POST["test"])) { $NewValue = $_POST["noGL" . $_POST["TLZno"]]; $TLZ = $_POST["TLZ"];?> <script> console.log ("test1"); </script> <?php $sql1 = "UpdateGL @CIE ='RAL', @TLZ='$TLZ', @NOGL='$NewValue'";?> <script> console.log ("test2"); </script> <?php } else { echo "Rien!"; } ?> <button class="btn btn-success btn-sm dropdown-toggle save" name='submit' id='submit' type="submit" value="Enregistrer"> <i class="fa fa-floppy-o fa-lg" aria-hidden="true"> Enregistrer</i> </button> <script> $(document).ready(function(){ $('.save').click(function(){ $('#GL_form').submit(); }); }); </script> </div><!-- Fin class pull-left--> <div class="panel panel-primary filterable"> <div class="panel-heading"> <h1 class="panel-title" style="font-weight:bold;">Liste des numéros de GL</h1> </div><!--Fin class panel-heading--> <div class="table-responsive"> <form id="GL_form" method="post" action="ListeGL.php"> <input type="hidden" id="test" name="test"/> <table id="employees" class="table table-highlight"> <thead> <tr class="filters" id="filters"> <th style="text-align: center;"># TLZ</th> <th style="text-align: left;">Description</th> <th style="text-align: center;">D/C</th> <th style="text-align: center;"># GL</th> <th style="text-align: left;">Nouveau # GL</th> </tr> </thead> <tbody> <?php $sql = "ListeGL"; $result = sqlsrv_query($conn, $sql); $row_count = sqlsrv_num_rows($result); while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) { //print_r( $row ); // debug code $couleur='black'; $font= 'normal'; $input="a"; if( strstr($row['HTML_CODE'], "BOLD()")){ $font= 'bold'; } if( strstr($row['HTML_CODE'], "BG()")){ $font2= '#D8D8D8'; } if( strstr($row['HTML_CODE'], "INPUT()")){ $input= 'input'; $font2= '#transparent'; } ?> <tr> <?php echo "<tr style=\"font-weight:$font; color:$couleur; background-color:$font2;\">"; ?> <td style="text-align: center;"><?php echo ($row['TLZno']); ?></td> <td style="text-align: left;"><?php echo ($row['TlzDescription']); ?></td> <td style="text-align: center;"><?php echo ($row['TlzType']); ?></td> <td style="text-align: center;"><?php echo ($row['noGL']); ?></td> <td style="font-weight: normal; text-align: left; color: #BDBDBD; "> <<?php echo $input . ' name="noGL' . $row['TLZno'] . '"'; ?> type="text" name="new" value="<?php echo ($row['noGL']); ?>" /> </td> </tr> <?php } ?> </tbody> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/303804-update-sql-server-db-in-php-with-stored-procedure/ Share on other sites More sharing options...
dalecosp Posted April 27, 2017 Share Posted April 27, 2017 (edited) My first advice would be skip AJAX for now and get the form and form handler working with a "good, old fashioned" page load. Once you are sure that POSTing to your form will update the DB as you require, then convert the form to use AJAX. (And, actually, what I usually do in these cases is write a simple but *separate* form to POST to the handler, and then discard it once I'm sure my handler's good). As for what is wrong otherwise, I don't know, but the first thing I'd check is what $_POST contains when the form is submitted. Edited April 27, 2017 by dalecosp Quote Link to comment https://forums.phpfreaks.com/topic/303804-update-sql-server-db-in-php-with-stored-procedure/#findComment-1545924 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.