2013-02-27 139 views
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"); 
    } 
} 
+0

这显然是太局限的问题。 – 2013-02-27 13:08:26

+0

因为它不必要? – user2031928 2013-02-27 13:08:57

回答

0

一个问题,我看到的是你的“回声”通话中“头(......)”你的检查更新程序,从而预期

的页面不会重定向前发出

引用“请记住,必须在发送任何实际输出之前调用header(),或者使用普通HTML标记,文件中的空行或PHP。” see PHP header manual