Jump to content

Update SQL Server DB in php with stored procedure

Recommended Posts


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"];?>
        console.log ("test1");
    <?php $sql1 = "UpdateGL @CIE ='RAL', @TLZ='$TLZ', @NOGL='$NewValue'";?>
        console.log ("test2");
        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>

</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">
             <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>
$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
    $font= 'normal';
    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';
                 <?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']); ?>" />

Share this post

Link to post
Share on other sites

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 by dalecosp

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.