dongtanxi5676756 2015-10-29 05:03
浏览 30

请使用以下代码解决错误

Shown below is the form for leave details (extracted from a table) of user where in after user checks the corresponding checkboxes the values get inserted into a table (code below this one)

<?php
session_start();
//$myusername=$_SESSION['myusername'];
if(!session_is_registered('myusername')){
//if(!session_register())

header("location:login_form.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Leave add form</title>
</head>

<body>
<table border="2" cellspacing="10pt" cellpadding="5pt">
<form method="post" action="leave_form_exec.php" >
<?php
include($_SERVER['DOCUMENT_ROOT'].'/db_connect_eadmin.php');
$qry = "select per_no, office, leave_typ, pre_fr, pre_to, leave_fr, leave_to, days, lev_rsn, lev_add, sl_no, leave_typ, can_no, appliedon, post, pmt_per_no, pmt_name from tbl_golevapp, pis_mstr_table where post='N' and tbl_golevapp.per_no=pis_mstr_table.pmt_per_no";
print('<center> <table border="2" rules="all" cellpadding="15" cellspacing="110">');
?><tr><th width=10%>Personnel no of Officer</th><th width=30%>NAME OF THE OFFICER</th><th width=30%> OFFICE</th> <th width=15%>LEAVE TYPE</th><th width=10%>LTC IN THIS PERIOD</th><th width=10%>LEAVE FROM</th><th width=10%>LEAVE TO</th><th width=10%>DAYS</th><th width=10%>LEAVE REASON</th><th width=100%>LEAVE ADDRESS</th><th width=100%>APPLICATION DATE</th><th width=20%>ENTER SANCTION DATE</th><th width=20%>SELECT THE CHECKBOX</th> </tr>
<?php
$recset=odbc_exec($congpass,$qry);
if (!$recset) {exit("Error in SQL"); }
while(odbc_fetch_row($recset))
{
  ?>
    <tr>
      <td>
        <?php 
        $row['per_no']=odbc_result($recset,1);
        $row['office']=odbc_result($recset,2);
        $row['leave_typ']=odbc_result($recset,3);
        $row['pre_fr']=odbc_result($recset,4);
        $row['per_to']=odbc_result($recset,5);
        $row['leave_fr']=odbc_result($recset,6);
        $row['leave_to']=odbc_result($recset,7);
        $row['days']=odbc_result($recset,8);
        $row['lev_rsn']=odbc_result($recset,9);
        $row['lev_add']=odbc_result($recset,10);
        $row['sl_no']=odbc_result($recset,11);
        $row['leave_typ']=odbc_result($recset,12);
        $row['can_no']=odbc_result($recset,13);
        $row['appliedon']=odbc_result($recset,14);
        $row['post']=odbc_result($recset,15);
        $row['name']=odbc_result($recset,17);
                   echo $row['per_no']; ?> </td>
        <td> <?php echo $row['name'];?></td>
        <td> <?php echo $row['office'];?></td>
        <td> <?php echo $row['leave_typ'];?></td>
         <td> <!--<input type="radio" name="ltc[]" value="yes" /> <strong>YES</strong>
            <input type="radio" name="ltc[]" value="no" /> <strong>NO</strong>--></td> 
        <td> <?php echo $row['leave_fr'];?></td>
        <td> <?php echo $row['leave_to'];?></td>
        <td> <?php echo $row['days'];?></td>
        <td> <?php echo $row['lev_rsn'];?></td>
        <td> <?php echo $row['lev_add'];?></td>
        <!--<td> <?php echo $row['leave_typ'];?></td>-->
        <td> <?php echo $row['appliedon'];?></td>
        <!-- HIDDEN INPUT KD STYLE :)-->
        <input type="hidden" name="per_no[]" value="<?php echo $row['per_no']; ?>">
        <input type="hidden" name="leave_typ[]" value="<?php echo $row['leave_typ']; ?>">
        <input type="hidden" name="appliedon[]" value="<?php echo $row['appliedon']; ?>">
        <input type="hidden" name="leave_fr[]" value="<?php echo $row['leave_fr']; ?>">
        <input type="hidden" name="office[]" value="<?php echo $row['office']; ?>">
        <input type="hidden" name="leave_to[]" value="<?php echo $row['leave_to']; ?>">
        <input type="hidden" name="sl_no[]" value="<?php echo $row['sl_no']; ?>"><br />
        <td align="center"><input type="text" name="sanction_date" > Enter Sanction Date in DDMMYYYY <br /></td>
        <input type="hidden" name="days[]" value="<?php echo $row['days']; ?>">
        <td align="center"><input type="checkbox" name="name[]" value="<?php echo $row['sl_no']; ?>"></td>
        </tr>
        <?php //$i=$i+1;?>
  <?php
} /* END OF WHILE LOOP */
?>
<br />
<table align="center">
<tr>
<td><input type="submit" value="save" id="submit"></td>
</tr>
</table>
<br /> <br /> <br /> <br /> <br /> <br /> <br /> <br />
 <!-- FORM CLOSE -->
</table>
</form>
</body>
</html>

values are then inserted through the following code

<?php
session_start();
if(!session_is_registered(myusername)){
header("location:login_form.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Leave form execute</title>
</head>

<body>
<?php
include($_SERVER['DOCUMENT_ROOT'].'/db_connect_eadmin.php');
$qry_form="select max(transact_no) from leave_transactions";
$recset=odbc_exec($congpass,$qry_form);
if (!$recset) {exit("Error in SQL"); }
while(odbc_fetch_row($recset))
{
$transact=odbc_result($recset,1);
}
$counter = count($_POST["name"]); /* COUNT THE PASSED ON NAME */
echo $counter;// Echo for check
//echo $_POST["name"];

  for($x=0; $x<=$counter; $x++){
    echo $_POST["name"][$x]; // Echo for check
    if(!empty($_POST["name"][$x]))
    {
        echo $_POST["name"][$x];// Echo for check
       $transact=$transact+1;
      $p_no = $_POST['per_no'][$x];
      echo $p_no;// Echo for check
      $s_no = $_POST['sl_no'][$x];
    //  $ = $_POST['piaddress'][$x];
      if(($_POST['appliedon'][$x])<($_POST['leave_fr'][$x]))
      {
      $nbtd='NORMAL';
      }
      else
      {
      $nbtd='BKDTD';
      }
      $leave_typ = $_POST['leave_typ'][$x];
      if(($_POST['days'][$x])==0.5)
      {
      $hdcl='Y';
      }
      else
      {
      $hdcl='N';
      }
      $office=$_POST['office'][$x];
      $appliedon=$_POST['appliedon'][$x];
      $lv_fr=$_POST['leave_fr'][$x];
      $lv_to=$_POST['leave_to'][$x];
      $sanc_date=$_POST['sanction_date'];
      $ltc=$_POST['ltc'];
      $days=$_POST['days'][$x];
      $qry="INSERT INTO leave_transactions(transact_no,  
      personnel_no, 
      section_code,
      normal_or_bkdtd,  
      leave_type,      
      half_day_cl,
      half_day_ind,
      application_date,
      from_date,      
      to_date,       
      sanction_date,
      mc_code ,
      sanct_auth,
      leave_days )
      VALUES 
('$transact','$p_no','$office','$nbtd','$leave_typ','$hdcl',NULL,'$appliedon','$lv_fr','$lv_to',
      '$sanc_date',0,'GENERAL MANAGER/OITC','$days')";
                            echo $qry;
      $recset=odbc_exec($congpass,$qry);
      if(!$recset) 
      {
        die("ERROR !!!!! QUERY NOT INSERTED");
      }
      $qr1="update tbl_golevapp set post='Y' where sl_no='$s_no' && per_no='$p_no' && post='N'";
      $recset1=odbc_exec($congpass,$qr1);
      echo "<strong> VALUES SUCCESSFULLY INSERTED </strong>";
    } /* END OF CHECKING THE CHECKBOX IF SELECTED */
  } /* END OF FOR LOOP */

?>
</body>
</html>

but instead only the first row values as echoed in the preceding code are inserted (with an error since in $qr1="update tbl_golevapp set post='Y' where sl_no='$s_no' && per_no='$p_no' && post='N'";) .... and on insert it is picking only the first row as displayed

  • 写回答

1条回答 默认 最新

  • douhanzhen8927 2015-10-29 05:16
    关注

    && are not supported in sql query. You need to replace it with AND.

    Try changing:

    $qr1="update tbl_golevapp set post='Y' where sl_no='$s_no' && per_no='$p_no' && post='N'";
    

    to

    $qr1="update tbl_golevapp set post='Y' where sl_no='$s_no' and per_no='$p_no' and post='N'";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误