下面显示的是用户的离开详细信息(从表中提取)的表单,在用户检查相应的复选框后,值将被插入到表中(代码低于此表)
<?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>
然后通过以下代码插入值
<?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>
但是只插入前面代码中回显的第一行值(在$qr1="update tbl_golevapp set post='Y' where sl_no='$s_no' && per_no='$p_no' && post='N'";
中有错误)....在插入时,它只选择显示的第一行
答案 0 :(得分:0)
&&
。您需要将其替换为AND
。
尝试更改:
$qr1="update tbl_golevapp set post='Y' where sl_no='$s_no' && per_no='$p_no' && post='N'";
到
$qr1="update tbl_golevapp set post='Y' where sl_no='$s_no' and per_no='$p_no' and post='N'";