我创建了一个包含很少属性代码的表
<table class="table table-hover table-striped">
<thead>
<tr>
<th>Id</th>
<th>File-name</th>
<th>Purpose</th>
<th>Recieved-By </th>
<th>Processed-By</th>
<th>Adress</th>
<th>Contact-No</th>
<th>Date</th>
<th>Update</th>
</tr>`
这里是从更新
以外的所有列中的数据库表中获取数据 <tbody>
<?php
if ( $search )
{
$p_query = "select * from files where recieved_by like '%$search%' or processed_by like '%$search%' or purpose like '%$search%' or file_name like '%$search%' order by id desc limit $page_start_from, $total_num_page";
}
else
{
$p_query = "select * from files order by id desc limit $page_start_from, $total_num_page";
}
$p_run=mysqli_query($con,$p_query);
if(mysqli_num_rows($p_run)){
while($row=mysqli_fetch_array($p_run))
{
$c_id=$row['id'];
$file=$row['file_name'];
$purpose=$row['purpose'];
$recieve=$row['recieved_by'];
$processed=$row['processed_by'];
$address=$row['address'];
$contact=$row['contact_no'];
$date=$row['date'];
$show_status=$row['show_status'];
?>
<tr>
<td><a href="post.php?post_id=<?php echo $c_id?>"><?php echo $c_id;?></a></td>
<td><a href="post.php?post_id=<?php echo $c_id?>"><?php echo $file;?></a></td>
<td><a href="post.php?post_id=<?php echo $c_id?>"><?php echo $purpose;?></a></td>
<td><a href="post.php?post_id=<?php echo $c_id?>"><?php echo $recieve;?></a></td>
<td><a href="post.php?post_id=<?php echo $c_id?>"><?php echo $processed;?></a></td>
<td><a href="post.php?post_id=<?php echo $c_id?>"><?php echo $address;?></a></td>
<td><a href="post.php?post_id=<?php echo $c_id?>"><?php echo $contact;?></a></td>
<td><a href="post.php?post_id=<?php echo $c_id?>"><?php echo $date;?></a></td>
现在在更新列中,当更新列中的值来自文件表数据库时会发生更改,然后它会在更新列中显示,否则它将打开一个< strong>具有表单代码的<按钮操作
<td>
<?php if( !empty($show_status)){
echo $show_status;
}
else
{
?>
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style=" padding-top: 3px; padding-bottom: 3px;">
Action <span class="caret"></span>
</button>
<ul class="dropdown-menu" style="margin-left:-50px;">
<?php
if(isset($_POST['submit-form']))
{
$update_date=$_POST['reason-date'];
$status=$_POST['reason'];
$p_id=$_POST['idvalue'];
$d_query="INSERT INTO update_table (id, reason, update_date) VALUES ('$p_id', '$status', '$update_date'); update files set show_status =' $status' where id=' $p_id'";
if(mysqli_multi_query($con,$d_query))
{
$msg="file have been submitted ";
header('location:index.php');
}
else
{
$error_msg="Already updated this file";
}
}?>
<script type="text/javascript">
function checkvalue()
{
var ureason=document.forms["sform"]["ureason"].value;
var udate=document.forms["sform"]["udate"].value;
if (ureason=="")
{
alert("Status Field is blank ");
return false;
}
if (udate=="")
{
alert("Date Field is blank ");
return false;
}
}
</script>
<form role="banner" class="actionform" action="index.php" method="POST" name="sform" onsubmit=" return checkvalue()">
<input type="hidden" name="idvalue" value="<?php echo $c_id; ?>">
<label style="font-weight: normal;">Enter Reason*</label><br>
<input type="text" name="reason" placeholder="call or letter or filed " id="ureason"><br>
<label style="font-weight: normal;">Update Date:*</label><br>
<input type="date" name="reason-date" placeholder="enter date here" id="udate">
<br><br>
<input type="submit" name="submit-form" id="actionid" value="Submit" style="background: #3596e0; ">
<?php
if(isset($error_msg))
{
echo "<span style='color:red; margin-bottom:10px;' class='pull-right'>$error_msg</span>";
exit();
}
else if(isset($msg))
{
echo "<span style='color:green;' class='pull-right'>$msg</span>";
exit();
}?>
</form>
</ul>
</div>
<?php
} ?>
</td>
</tr>
<?php
}
}
else {
echo "<h3> NO Related Table is Found Here </h3>";
}
?>
</tbody>
</table>
现在的问题是,当我正在填写第一次更新动作形式正常但是当我要进行第二次或第三次动作以上行更新功能未填充其保持显示检查表格列的错误是空的,如何停止这个,当我填写一行更新列时,它应该只影响那个特定的行,请有人帮助我,我坚持这个部分两天。
答案 0 :(得分:1)
由于您使用的是INSERT
方法,请使用UPDATE
方法进行更新。
首次由于没有数据,您的INSERT
方法可以正常工作,但之后您必须使用UPDATE
方法进行更新。
如需更新,请参阅https://www.w3schools.com/sql/sql_update.asp
对于INSERT,请参阅https://www.w3schools.com/sql/sql_insert.asp
答案 1 :(得分:0)
发生这种情况是因为您的表单值不是唯一形式,所以我更改了一些表单值:
<form role="banner" class="actionform" action="test.php" method="POST" name="sform" **onsubmit=" return checkvalue(<?php echo $c_id ?>**)">
<input type="text" name="reason" placeholder="call or letter or filed " id="ureason_<?php echo $c_id ?>">
<input type="date" name="reason-date" placeholder="enter date here" id="udate_<?php echo $c_id ?>">
现在所有ID都具有唯一价值,现在javascript代码将是:
<script type="text/javascript">
function checkvalue(id)
{
var id = id;
alert(id);
var ureason=document.getElementById('ureason_'+id).value;
var udate=document.getElementById('udate_'+id).value;
if (ureason=="")
{
alert("Status Field is blank ");
return false;
}
if (udate=="")
{
alert("Date Field is blank ");
return false;
}
}
</script>
还有一个人认为您错过了更新表格文件
在插入更新表时同时运行此查询:
$d_query=$db->query("INSERT INTO update_table (id, reason, update_date) VALUES ('$p_id', '$status', '$update_date')");
$d_query=$db->query("Update files set show_status='ok' where id='$p_id' ");
我希望这对你有所帮助。