duanbo2048 2016-02-22 13:36
浏览 66

mysql UPDATE和刷新页面

I've got an issue where the page refreshes faster than the query is executed.

I use an UPDATE query to update my database with some values in my fields. And I got this under a button. But When I push this button (Which will refresh my website) it still shows the old values in my fields.

When I refresh the page again, it shows the values that I filled in. I added a image for a better explanation.enter image description here

I execute the query for getting the information for the table right away in my php code:

$dates = getStartAndEndTime($currentWeek, $currentYear);

$Query = "SELECT * FROM Productielijn1 WHERE Datum BETWEEN ? AND ? ORDER BY Datum";
if($stmt = $dbCon->prepare($Query))
{
    $stmt->bind_param('ss', $dates[0], $dates[1]);

    if( $stmt->execute() === TRUE)
    {
        $Result = $stmt->get_result();

        while($row = $Result->fetch_assoc())
        {
            $ArrayGegevens[] = $row;
        }
    }   
}

And when I press the button I do this:

//First edit button
if(isset($_POST['btnEdit1']))
{
    $date = strip_tags($_POST['Datum1']);

    $tempo = strip_tags($_POST['Tempo1']);
    $proddescrip = strip_tags($_POST['Productomshrijving1']);
    $amount = strip_tags($_POST['Aantal1']);

    $displayDate = date("d-m-Y", strtotime($date));

    $Query = "UPDATE productielijn1 SET Tempo= ?, Productomschrijving= ?, Aantal= ? WHERE Datum = ?";

    if($stmt = $dbCon->prepare($Query))
    {
        $stmt->bind_param('isis', $tempo, $proddescrip, $amount, $date);

        if( $stmt->execute() === TRUE)
        {
            $Message2 = "De waardes van " . $displayDate ." zijn aangepast.";
            $MessageColor2 = "green"; 
        }
        else
        {
            $Message2 = "Het aanpassen is niet gelukt!";
            $MessageColor2 = "red"; 
        }
    }   
}

And I create my table like this:

    <table class ="PlanningTable">
        <tr>
            <th colspan='5'>Planning aanpassen voor huidige week (<?php echo $currentWeek ?>)</th>
        </tr>
        <tr>
            <th>Datum</th>
            <th>Tempo</th>
            <th>Product omschrijving</th>
            <th>Aantal/Volume</th>
            <th>Aanpassen</th>
        </tr>

        <?php
        if (count($ArrayGegevens) != 0)
        {
            for ($k = 1; $k < count($ArrayGegevens)+1; $k++)
            {
                echo "<tr>";
                echo "<td><input type='date' name='Datum".$k."' value='".$ArrayGegevens[$k-1]['Datum']."'readonly></td>";
                echo "<td><input type='number' name='Tempo".$k."' value= '" .$ArrayGegevens[$k-1]['Tempo'] . "'></td>";
                echo "<td><input type='text' name='Productomshrijving".$k."' value ='". $ArrayGegevens[$k-1]['Productomschrijving'] ."'></td>";
                echo "<td><input type='number' name='Aantal".$k."' value='" . $ArrayGegevens[$k-1]['Aantal'] . "'></td>";
                echo "<td><input type='submit' name='btnEdit".$k."' value='Aanpassen'></td>";
                echo "</tr>";
            }   
        }
        else
        {
            echo"<tr>";
            echo "<td colspan='5' style='color: red;'>Voor deze week is er nog geen planning!</td>";
            echo "</tr>";
        }

        ?>
        <tr>
            <td colspan=5><p class="Message" style='color: <?php echo $MessageColor2 ?>;'><?php echo $Message2 ?></p></td>
        </tr>
    </table>

So is there a way that it will update my html values right away?

  • 写回答

1条回答 默认 最新

  • douyanjing0822 2016-02-22 13:57
    关注

    Change your code to:

    <!-- language: lang-html -->
    
        if(isset($_POST['btnEdit1']))
        {
            $date = strip_tags($_POST['Datum1']);
    
            $tempo = strip_tags($_POST['Tempo1']);
            $proddescrip = strip_tags($_POST['Productomshrijving1']);
            $amount = strip_tags($_POST['Aantal1']);
    
            $displayDate = date("d-m-Y", strtotime($date));
    
            $Query = "UPDATE productielijn1 SET Tempo= ?, Productomschrijving= ?, Aantal= ? WHERE Datum = ?";
    
            if($stmt = $dbCon->prepare($Query))
            {
                $stmt->bind_param('isis', $tempo, $proddescrip, $amount, $date);
    
                if( $stmt->execute() === TRUE)
                {
                    $Message2 = "De waardes van " . $displayDate ." zijn aangepast.";
                    $MessageColor2 = "green"; 
                }
                else
                {
                    $Message2 = "Het aanpassen is niet gelukt!";
                    $MessageColor2 = "red"; 
                }
            }
    
                  echo "<script>
                    setTimeout(function(){
                        location.reload();
                    }, 300);
                    </script>";
    
    
    }
    

    Adding js code.

    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题