簡體   English   中英

停止在刷新瀏覽器中插入空白數據

[英]Stop Inserting Blank data in Refreshing browser

我是PHP的新手。 請刷新瀏覽器時,請幫助停止插入空白數據。 我正在嘗試從HTML表單中插入SQL數據庫中的數據,並將它們顯示在表格的同一頁面中。 這是我的來自&PHP代碼在此先感謝....

</head>
<body>


        <?php
    $sub = mysql_connect ("localhost", "root","");
    if (!$sub)
    {
        die('Could Not Connect:'.mysql_erro());
    }
    mysql_select_db("test", $sub);
    $sql="INSERT INTO te(Dat,Sadi,Jam,Washi) VALUES('$_POST[Dat]','$_POST[Sadi]','$_POST[Jam]','$_POST[Washi]')";
    if (!mysql_query($sql, $sub))
    {
        die('Error:'.mysql_error());
    }

    echo 'One Record added';

            $result=mysql_query("SELECT * FROM te");
            echo "<table border='1'>;
            <tr>
            <th>Date</th>
            <th>Sadi</th>
            <th>Jam</th>
            <th>Washi</th>
            </tr>";
            while ($row = mysql_fetch_array($result)) 
            {
            echo "<tr>";
            echo "<td>" .$row['Dat']."</td>";
            echo "<td>" .$row['Sadi']."</td>";
            echo "<td>" .$row['Jam']."</td>";
            echo "<td>" .$row['Washi']."</td>";
            echo "</tr>";
            }
            echo "</table>";
            Mysql_close($sub);
            ?>
    </body>

    <form action="index.php" method="post">
        <input type="text" name="Dat" placeholder="Date, DD-MM-YY">
        <input type="text" name="Sadi" placeholder="Sadi">
        <input type="text" name="Jam" placeholder="Jam">
        <input type="text" name="Washi" placeholder="Washi">
        <input type="submit" name="sub">
    </form>

只需驗證$_POST是否為空

if(!empty($_POST))
{
    $sql="INSERT INTO te(Dat,Sadi,Jam,Washi) VALUES('$_POST[Dat]','$_POST[Sadi]','$_POST[Jam]','$_POST[Washi]')";
    if (!mysql_query($sql, $sub))
    {
        die('Error:'.mysql_error());
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM