2017-02-09 75 views
1

我用提交按钮创建了一个表单。如果“价格”特定产品已经填满,然后提交按钮必须禁用:填写数据库字段后禁用提交按钮

enter image description here

代码的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>"; 
    } 
?> 

只有一次,如果已经进入那么价格应该进入发送按钮应该被禁用

每当我加载这个页面,它应该检查数据库,如果价格值是fi那么它应该禁用发送按钮。

+0

代码在哪里? – prasanth

+0

检查代码。 – Raahul

回答

0

使用下面的代码在提交按钮:

<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

它会...但下一次当我再次加载此页面时,它将显示 – Raahul

+0

然后,您需要在查询中添加价格,并检查是否为空,然后添加下面的代码,否则执行给定的代码。禁用 – Gmnayem

+0

可以发送代码吗?如果查询包含值,如何添加onclick? – Raahul

0

首先你会在数据库产品的价格检查是否可用,如果价格可以再设置变量0不可用可用或1;