【问题标题】:No error shown when updating and deleting更新和删除时没有显示错误
【发布时间】:2015-10-27 10:57:10
【问题描述】:

我有那些代码可以帮助更新和删除表中的一行:

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"); 

    }
}
?>

没有更新或删除任何内容。并且没有显示错误。如果有人可以帮助我,我认为问题太简单但看不到哪里。

【问题讨论】:

  • 好吧,您可能不会看到错误,因为您在看到错误之前就重定向了.. + 您没有发布任何内容,因为您的表单仅涵盖提交按钮,而不是您的输入字段寻找...
  • 你能修复代码吗?

标签: php html


【解决方案1】:

您将&lt;form&gt; 标签放置在错误的位置。

因此,您的其他元素:idmed_nameinfo 不是 form 的子元素。

他们没有被发布。

&lt;form&gt; 应该在表格之前开始,在表格之后结束。

更正的代码:

<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>

【讨论】:

  • 先生,我需要在 td 中回显 id 并使用 id 号进行更新。如何通过在 td 中回显 id 并在操作页面中获取值来做到这一点?
  • 是的,我想获取行的 id 以更新 t 而不显示在带有名称标签的 TD 中。如果你没有明白我的意思,我可以解释更多
  • 我需要获取每一行的id而不在页面上显示id
【解决方案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>

【讨论】:

  • 表格内的表格我猜是行不通的......只是交叉检查。
  • @NiranjanNRaju 表格与表格无关......只是需要提交的值应该放在表格中......
  • @ManojSalvi 你能解释一下吗?
  • @NiranjanN Raju 看看这个stackoverflow.com/questions/3622405/…
  • td 里面的表格没问题,但是表格后面的表格就不行了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-19
相关资源
最近更新 更多