2011-06-03 36 views
0

當我點擊更新按鈕它不會更新表,但是當我再次點擊它將被更新如何糾正它?提交按鈕將不會顯示結果通過一次點擊它會顯示它通過第二次點擊

<html> 
<head> 
<title>pharmacy</title> 
<form method="post"> 
<?php 
session_start(); 
$connection=Mysql_connect('localhost','admin','123'); 
Mysql_select_db('db',$connection); 
$pname=$_SESSION['s1']; 
$query="select * from request where ph='$pname'"; 
if(array_key_exists('rqlist',$_POST)) 
{ 
     if(!$connection) 
     { 
     echo 'connection is invalid'; 
     } 
     else 
     { 

      $result=mysql_query($query); 
      if($result) 
      { 
      $num=Mysql_num_rows($result); 
      $num1=Mysql_num_fields($result); 
      echo $num; 
        if($num>0) 
        { 
        echo "<table border=2> Table Request".$_SESSION['s1']; 
        echo"<tr> 
        <td>Id</td><td>Drug</td><td>Quantity</td><td>Doctor</td><td>       </td><td>pharmacy</td><td>name</td><td>lastname</td><td>Situation</td> 
          </tr>"; 
     for($i=0;$i<$num;$i++) 
     { 
     $row=mysql_fetch_row($result); 

     echo "<tr>"; 
     for($j=0;$j<$num1;$j++) 
     { 
     echo"<td>$row[$j]</td>";  
     } 
     echo"<td><input type='Checkbox' name='p[$i]' value='on' unchecked />  </td>"; 
     echo"</tr>"; 
     } 
     } 
    } 
    }//else 
    }//array 
    if(array_key_exists('update',$_POST)){ 
      $result=mysql_query($query); 
      $qut="select qun from $pname"; 
      $rt=mysql_query($qut); 
      if($result && $rt) 
      { 
      $num=Mysql_num_rows($result); 
      $num1=Mysql_num_fields($result); 
      //num2=Mysql_num_rows($rt); 
     if($num>0) 
     { 
     echo "<table border=2> Table Request".$_SESSION['s1']; 
     echo"<tr> 
     <td>Id</td><td>Drug</td><td>Quantity</td><td>Doctor</td><td></td><td>pharmacy</td><td></td><td>Situation</td> 
     </tr>"; 
     for($i=0;$i<$num;$i++) 
     { 
     $row=mysql_fetch_row($result); 
     $row2=mysql_fetch_row($rt); 
     $dr[$i]=$row[1]; 
     $qu[$i]=$row[2]; 
     $st[$i]=$row[7]; 
     $qun[$i]=$row2[0]; 
     $query8="select * from $pname where name='$dr[$i]' and qun>$qu[$i] "; 
     $result8=mysql_query($query8); 
     $num8=Mysql_num_rows($result8); 
     if($num8!=0) 
     { 
      if($row[5]!='ready' && $row[5]!='transfer from $pname') 
      { 
     $query9="update request set situation='ready' where drug='$dr[$i]' "; 
     $qu="update $pname set qun=$qun[$i]-$qu[$i] where name='$dr[$i]' "; 
     $result9=mysql_query($query9); 
     $resultqu=mysql_query($qu); 
     echo $qu; 
      } 
     } 
     else{ 
     if($row[5]!='ready'&&$row[5]!='transfer from $pname') 
      { 
     $query10="update request set situation='transfer from $pname' where drug='$dr[$i]' "; 
     $result10=mysql_query($query10); 
      } 
     } 
     echo "<tr>"; 
     for($j=0;$j<$num1;$j++) 
     { 
     echo"<td>$row[$j]</td>";  
     } 
     echo"<td><input type='Checkbox' name='p[$i]' value='on' unchecked /></td>"; 
     echo"</tr>"; 
     }//for$i 
     echo"</table>"; 
     }//if num 
     } 
     } 
?> 
<input type="submit" name="rqlist" value="Request list"/> 
<input type="submit" name="update" value="Update the list"/> 
</form> 
</head> 
</html> 

回答

0

嘗試取出請求列表按鈕,看看它是否有什麼變化

+0

對不起你能解釋一下你的意思?我不明白 – Nickool 2011-06-03 10:12:13

+0

我的意思是,你應該嘗試採取了'<輸入類型=「submit」name =「rqlist」value =「請求列表」/>'從您的表格 – boug 2011-06-03 10:13:09

+0

並將其添加到哪裏?你的意思是我必須在PHP中迴應它? – Nickool 2011-06-03 10:17:54

相關問題