簡體   English   中英

填寫數據庫字段后,禁用“提交”按鈕

[英]Disable Submit button once database field is filled

我用提交按鈕創建了一個表單。 如果特定產品的“價格”已經填寫,則必須禁用“提交”按鈕:

在此處輸入圖片說明

代碼php

<?php
  $host="localhost";
    $username="root";
    $password="";
    $db_name="ge";

    $con=mysqli_connect("$host", "$username", "$password","$db_name")or die("Your Connection is in error");
  $sql="SELECT pname,catogery,email FROM quetation WHERE catogery = '$catogery'";

    $results=mysqli_query($con,$sql);
  $count=mysqli_num_rows($results);
    if($count == 0) {
        echo "<font color=\"#0000\"><h1 align=\"center\">No details found</h1></font>";
    } else {
        $resource=mysqli_query($con,$sql);
        echo "<font color=\"#000000\">
        <h2 align=\"center\"></h2>
        <table align=\"center\" border=\"1\" width=\"50%\">
            <tr>
                <td><b>ProdName</b></td>
                <td><b>Catogery</b></td>
                <td><b>Price</b></td>
           </tr> ";
      while($result=mysqli_fetch_array($resource)) {
                echo "
            <div class=\"row\">
            <div class=\"input-field col s12\">
            <tr>
              <td>".$result[0]."</td>
              <td>".$result[1]."</td>
              <td>
                   <form name=\"abc\" methos=\"post\" action=\"postprice.php\">
                        <input type=\"submit\" value=\"send\">
                  </form>
               </td>
               </div>
               </div>
            </tr>";
          } echo "</table></font>";
    }
?>

如果已經輸入,則只能輸入一次價格,然后應禁用發送按鈕

每當我加載此頁面時,都應檢查數據庫,如果價格值已滿,則應禁用發送按鈕。

在提交按鈕中使用以下代碼:

<input type="submit" onClick="this.disabled=true;">

單擊提交按鈕后,將禁用該按鈕。 希望對您有幫助。

PLz嘗試此代碼,希望它能工作。

<?php
    $host="localhost";
    $username="root";
    $password="";
    $db_name="ge";

    $con=mysqli_connect("$host", "$username", "$password","$db_name")or die("Your Connection is in error");




    $sql="SELECT pname,catogery,email,price FROM quetation WHERE catogery = '$catogery'";

    $results=mysqli_query($con,$sql);

    $count=mysqli_num_rows($results);
    if($count == 0)
    {
            echo "<font color=\"#0000\"><h1 align=\"center\">No details found</h1></font>";
    }
    else
    {
       $resource=mysqli_query($con,$sql);
       echo "<font color=\"#000000\">
              <h2 align=\"center\"></h2>

            <table align=\"center\" border=\"1\" width=\"50%\">
            <tr>
            <td><b>ProdName</b></td>
            <td><b>Catogery</b></td>
            <td><b>Price</b></td>

</tr> ";

    while($result=mysqli_fetch_array($resource))
        {
        echo "

            <div class=\"row\">
    <div class=\"input-field col s12\">
<tr>
        <td>".$result[0]."</td>
        <td>".$result[1]."</td>
    <td><form name=\"abc\" methos=\"post\" action=\"postprice.php\">";
    if($result[3]==''){
     echo "<input type=\"submit\" value=\"send\" onClick='this.disabled=true;'>";
    } else {
        echo "<input type=\"submit\" value=\"send\" disabled>";
    } 
    echo "</td>
    </form>
    </div>
</div>
        </tr>";
        }echo "</table></font>";
        }

?>

首先,您將檢入數據庫產品價格是否可用(如果價格可用),然后將變量0設置為不可用,或將變量1設置為可用。

暫無
暫無

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

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