我编写了一个非常简单的脚本来更新不同列中的多个值。我的问题是,当我尝试更新列中的值时,它可以正常工作,但是在复选框的情况下,值插入不正确。
例如。如果我有 7 行要更新并且在选择选项中我选择 1 、 2 、 3 复选框并且我没有选择 4 5 并再次选择 6 7 然后在更新时选择 1 、 2 、 3 、4 、5 和留下 6 7 未选中
我在这里粘贴我的代码
形式
<?php include("db.php");
$id = $_GET['id'];
$tDate2=$_GET['tDate2'];
?> <form method="POST" style="width:50%" action="updatemonthly.php" >
<table id="rounded-corner">
<?php
$conn=mysql_connect("localhost","root","root") or die(mysql_error());
mysql_select_db("monthly_pmc_admin") or die(mysql_error());
$result1 = mysql_query("SELECT * from project_details where id ='$id' ;");
$row = mysql_fetch_assoc($result1);
$pno=$row['Project_No'];
$result = mysql_query("SELECT * from capex_phasing_data where Project_Number ='$pno' order by id ;");
?>
<thead>
<tr>
<th colspan="6" scope="col" class="rounded-company">Edit/ Delete Capex Graph Values</th>
<th scope="col" class="rounded-q1"> <?php echo $tProjNo ?></th>
<th scope="col" class="rounded-q4"></th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="7" class="rounded-foot-left" align="center"><input type="submit" name="submit" value="DELETE" id='myButton1' />
<input type="submit" name="submit" value="UPDATE" id='myButton1' />
<?php
echo
'<a href="../capex.php?id=' . $id . '&tDate2='.$tDate2.'"> Add New Capex Value</a>';
?></td>
<td class="rounded-foot-right"></td>
</tr>
<tr>
<td colspan="4" class="rounded-foot-left" align="center"> <?php
echo('<A hREF="http://10.26.162.84/graph1/default.aspx?id='.$pno .'&tDate2='. $tDate2. '" target="_blank"> View Graph </A>');?></td>
<td class="rounded-foot-right"></td>
</tr>
</tfoot>
<tr>
<th align='center'> Select to <br/>
Delete Record </th>
<th >Month</th>
<th>Planned Phasing </th>
<th>Actual Phasing </th>
<th>Select To Display Value in Graph</th>
</tr>
<?
for($i=1;$i<=mysql_num_rows($result);$i++) {
$row = mysql_fetch_assoc($result);
?>
<tr>
<td align='left' ><input type="checkbox" name="chk[]" value="<?=$row['id']?>" align='center' />
</td>
<td align='left'><input type="text" name="month[]" size="10" id="jj" value="<?php echo $row['Month'];?>" />
</td>
<td align='center' ><input name="planman1[]" size="50" type="text" id="rr" value="<?php echo $row['Planned_Phasing'];?>" />
</td>
<td align='center' ><input name="planman2[]" type="text" size="8" id="r1r" value="<?php echo $row['Actual_Phasing'];?>" />
</td>
<td align='center' ><input name="planman5[]" type="checkbox" id="r4r" <? if($row['Select_project']==1) {echo 'checked';} ?> />
</td>
<input type="hidden" name="rowid[]" value="<?=$row['id']?>" align='center' />
<input type="hidden" name="ProjNo" value="<?php echo $id; ?>">
<input type="hidden" name="tDate2" value="<?php echo $tDate2; ?>">
<!--<input type="hidden" name="ProjNo" value="<?php echo $tProjNo; ?>">-->
</td>
</tr>
<?php
}
?>
更新查询
<?php
session_start();
require_once('dbclass/database.php');
$myClass=new database();
//echo $_POST['name'];
$array=$_POST['rowid'];
$month=$_POST['month'];
$planman1=$_POST['planman1'];
$planman2=$_POST['planman2'];
$planman3=$_POST['planman3'];
$planman4=$_POST['planman4'];
$planman5=$_POST['planman5'];
$actuanman=$_POST['actuanman'];
$length=count($_POST['rowid']);
$chk=$_POST['chk'];
$projno=$_POST['ProjNo'];
$tDate2=$_POST['tDate2'];
if($_POST['submit']=='UPDATE'){
for($a=0;$a<$length;$a++){
$rid=$array[$a];
$array[$a];
$month[$a];
$planman1[$a];
$planman2[$a];
$planman3[$a];
$planman4[$a];
$planman5[$a];
$ac= $actuanman[$a];
if($ac=='on'){$ch=1;} else {$ch=0;}
if($planman5[$a]=='on'){$planman5[$a]='1';} else {$planman5[$a]='0';}
$sql="UPDATE capex_phasing_data set Month='".$month[$a]."', Planned_Phasing='".$planman1[$a]."' , Actual_Phasing='".$planman2[$a]."', Select_project='".$planman5[$a]."' where id='".$rid."'";
mysql_query($sql) or die();
header("location:#");
}
}