PHP方法似乎不起作用

时间:2018-01-19 18:17:52

标签: php mysql oop methods pdo

我在我的班级使用PHP方法,以便从MySQL表中更新一些数据:

public function EditBrands($title,$id)
{
    if(!empty($title)&&!empty($id))
    {
        $edit = $this->db->prepare("UPDATE products SET brand_title = ? WHERE brand_id = ?");
        $edit->bindParam(1,$title);
        $edit->bindParam(2,$id);
        $edit->execute();
    }
    else
    {
        header("Location: php/includes/errors/022.php");
        exit();
    }
}

我在这里称这种方法:

if(isset($_GET['brand_id'])){
    $id = $_GET['brand_id'];

    if(isset($_POST['submit'])){
        $do = new Products();
        $title = $_POST['title'];
        $do->EditBrands($title,$id);
        echo '<META HTTP-EQUIV="Refresh" Content="0; URL=brandmanagement.php?action=done">';   
        exit; 
    }
    if(isset($_POST['back'])){
        echo '<META HTTP-EQUIV="Refresh" Content="0; URL=brandmanagement.php">';    
        exit; 
    }

<form action='' method='POST'>
  <input type='text' name='title'></input>
</form>
}

但问题是,它不会更新并将product_title更改为新的。我不知道为什么,但我的代码看起来很好而且很完美。此外,我没有收到任何错误消息。

1 个答案:

答案 0 :(得分:0)

我猜你必须给你的表单命名。改变这个

     <form action='' method='POST'>

     <form action='' method='POST' name='submit'>

为了更好地查找并且不混合代码,为代码示例提供空格

    if(!empty($title)&&!empty($id))

    if(!empty($title) && !empty($id))