0

我想有一种更清洁的方法,但我试图归档我可以在更新表单中编辑数据。问题是更新查询不起作用。谁能指出所犯的错误。不管怎么说,还是要谢谢你。

public function editData()
{
    if (isset($_GET['pid']))
    {
        $target = $_GET['pid'];
        if($edit = $this->db->prepare("SELECT id, title, price, description, address, includ, duration FROM trips WHERE id=?"))
        {
            $edit->bind_param('i', $target);
            $edit->execute();
            $edit->store_result();
            $edit->bind_result($id, $name, $price, $description, $address, $includ, $duration);
            $edit->fetch();
            $this->editForm($id, $name, $price, $description, $address, $includ, $duration);
        }
        else
        {
            echo "something went wrong";
        }
    }
}

public function editForm($id, $name, $price, $description, $address, $includ, $duration)
{
    $add .= '<form name="invent" method="post"  action="index.php?res=resources&adm=admin&page=inventory.php&pid=$id" class="ínvent" enctype="multipart/form-data">';
    $add .= '<fieldset>';
    $add .= '<legend>Add products</legend>';
    $add .= "<label for='name'></label>";
    $add .= "<input type='text' name='user' value='".$name."' />";
    $add .= '</br>';
    $add .= "<label for='price'>price</label>";
    $add .= "<input type='number' name='price' value='".$price."'  />";
    $add .= '</br>';
    $add .= "<label for='description'>description</label>";
    $add .= "<textarea name='description' rows='10' cols= '80'>'".$description."' </textarea>";
    $add .= '</br>';
    $add .= "<label for='address'>address</label>";
    $add .= "<input name='address'  type='text' value='".$address."'>";
    $add .= '</br>';
    $add .= "<label for='include'>Including</label>";
    $add .= "<input name='include'  type='text' value='".$includ."'>";
    $add .= '</br>';
    $add .= "<label for='duration'>duration</label>";
    $add .= "<input name='duration'  type='text' value='".$duration."'>";
    $add .= '</br>';
    $add .= "<label for='img'>img</label>";
    $add .= "<input name='image'  type='file'>";
    $add .= '</br>';
    $add .="<input type='submit' name='update'/>";
    $add .= '</fieldset>';
    $add .= '</form>';
    echo $add;

    if(isset($_POST['update']))
    {   
        $update_name = $_POST['user'];
        $update_price = $_POST['price'];
        $update_description = $_POST['description'];
        $update_address = $_POST['address'];
        $update_includ = $_POST['include'];
        $update_duration = $_POST['duration'];

        if ($update = $this->db->prepare("UPDATE trips SET title = ?, price = ? , description = ?, address = ?, includ = ?, duration = ?  WHERE id=?"))
        {
            $update->bind_param("ssssssi", $update_name, $update_price, $update_description, $update_address, $update_includ, $update_duration, $id);
            $update->execute();
        }
        else
        {
            echo "couldnt update";
        }
        header("Location: index.php?res=resources&adm=admin&page=inventory.php");
    }
}
4

1 回答 1

0

one issue i see is that you issue an "echo" before calling "header(...)" in your update check routine so the page will not redirect as intended

Quote "Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP." see PHP header manual

于 2013-02-27T13:07:58.533 回答