提交按钮不会通过单击显示结果,它将通过第二次单击显示它

时间:2011-06-03 09:26:42

标签: php mysql post submit

当我点击更新按钮时,它不会更新表格,但是当我再次点击它时,它会更新如何更正它?

<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>

1 个答案:

答案 0 :(得分:0)

尝试取出请求列表按钮以查看是否有任何更改