2015-10-27 110 views
0

时所显示的错误,我有那些帮助更新和删除表中的一行代码:没有更新和删除

HTML:

<table class="imagetable" cellpadding="3" cellspacing="1" width="400px" border="1"> 
    <th>ID</th> 
    <th>Name</th> 
    <th>Informations</th> 
    <th>Actions</th> 
    <tr> 
     <td><input type="text" name="id" value="<?php echo $rows['id'] ?>"/></td> 
     <td><input type="text" name="med_name" value="<?php echo $rows['med_name'] ?>"/></td> 
     <td><input type="text" name="info" value="<?php echo $rows['info']?>"/></td> 
     <td> 
      <form action="update_del.php" method="post"> 
       <input class="imgClass_update" type="submit" name="submit1" value="" /> 
       <input class="imgClass_dell" type="submit" name="submit2" value=""/> 
      </form> 
     </td> 
    </tr> 
    <tr> 

PHP:

<?php 
require_once('../include/global.php'); 
$id=$_POST['id']; 
if(isset($_POST['submit1'])) 
{ 
    $name=$_POST['med_name']; 
    $info=$_POST['info']; 

    $sql = "UPDATE med SET med_name='$name', 
          info='$info' 
          WHERE id='$id'"; 
    $result=mysqli_query($con,$sql) or die('Unable to execute query. '. mysqli_error($con)); 

    if($result){ 
     header("location:med.php"); 
    } 
    else 
    { 
     header("location:update_false.php"); 

    } 
} 
if(isset($_POST['submit2'])) 
{ 
    $sql = "DELETE FROM med WHERE id='$id'"; 
    $result=mysqli_query($con,$sql) or die('Unable to execute query. '. mysqli_error($con)); 
    if(mysqli_affected_rows($con) == 1) 
    { 
     header("location:med.php"); 
    } 
    else 
    { 
     header("location:update_false.php"); 

    } 
} 
?> 

没有什么更新或删除。并没有显示错误。如果有人可以帮助我,我认为这个问题太简单了,但是看不到它在哪里。

+0

那么你的概率将不会看到错误,因为您重定向之前,你甚至可以看到一个错误.. +你不张贴任何东西因为你的表单只包含提交按钮,而不是你正在寻找的输入字段...... – Naruto

+0

你能修复代码吗? – droidnation

回答

3

您正在将<form>标签放置在错误的地方。

因此,你的其他元素:idmed_nameinfo没有的form孩子。

而他们没有得到张贴。

您应该在表格之前开始<form>并在表格之后结束。

更正代码:

<form action="update_del.php" method="post"> 
<table class="imagetable" cellpadding="3" cellspacing="1" width="400px" border="1"> 
<tr> 
<th>ID</th> 
<th>Name</th> 
<th>Informations</th> 
<th>Actions</th> 
</tr> 
<tr> 
<td><input type="text" name="id" value="<?php echo $rows['id'] ?>"/></td> 
<td><input type="text" name="med_name" value="<?php echo $rows['med_name'] ?>"/></td> 
<td><input type="text" name="info" value="<?php echo $rows['info']?>"/></td> 
<td> 
<input class="imgClass_update" type="submit" name="submit1" value="Update" /> 
<input class="imgClass_dell" type="submit" name="submit2" value="Delete"/>   
</td> 
</tr> 
</table> 
</form> 
+0

你能解决这个问题吗? – droidnation

+0

@droidnation,已更新的答案,请立即检查。 – Pupil

+0

先生,我需要回显td内的id并使用id号码进行更新。如何通过在td中回显id并获取操作页面中的值来实现该目的? – droidnation

2

只是这样做 -

<table class="imagetable" cellpadding="3" cellspacing="1" width="400px" border="1"> 
<form action="update_del.php" method="post"> 
<th>ID</th> 
<th>Name</th> 
<th>Informations</th> 
<th>Actions</th> 
<tr> 
<td><input type="text" name="id" value="<?php echo $rows['id'] ?>"/></td> 
<td><input type="text" name="med_name" value="<?php echo $rows['med_name'] ?>"/></td> 
<td><input type="text" name="info" value="<?php echo $rows['info']?>"/></td> 
<td> 

<input class="imgClass_update" type="submit" name="submit1" value="" /> 
<input class="imgClass_dell" type="submit" name="submit2" value=""/> 

</td> 
</tr> 
</form> 
+0

表格内表格不工作我猜...只是交叉检查。 –

+0

@NiranjanNRaju以及表格与表格无关....它只需要提交的值应该放在表格里面...... –

+0

@ManojSalvi你能解释一下吗? – droidnation