【发布时间】:2015-11-02 01:56:03
【问题描述】:
我的Update.php 文件:
<?php ob_start();
session_start();
//declare the basic variables
$servername = "localhost";
$username = "bilal";
$password = "super";
$dbname = "coursework";
//create connection
$link = mysqli_connect($servername, $username, $password, $dbname);
//check connection
if($link->connect_error){
die ("connection failed: " . $link->connect_error);
}
//Security purpose, handiling escape string
// $crested_by = $_POST ['created_by'];
$title = $_POST['title'];
$catagory = $_POST['catagory'];
$contact = $_POST['contact'];
$comment = $_POST ['description'];
$ses = $_SESSION['email'];
$date = date('Y-m-d');
$availability = $_POST ['availability'];
$price = $_POST ['price'];
$id = $_POST['wow'];
// $created_by_id = $_SESSION['created_by_id'];
// $username = $_SESSION['firstname'];
if (isset($_POST['del'])){
$deletequery=mysqli_query($link,"DELETE FROM new_post WHERE id='$id'");
header ("Location: added_posts.php");
}
else if(isset($_POST['update'])){
$sql = "UPDATE new_post SET title='$title', contact='$contact', availability='$availability', price='$price', comment='$comment' WHERE id='$id'";
if (mysqli_query($link, $sql)){
echo "awesoke";
header("Location:added_posts.php");
}else{
echo "Error: Sign up Unsuccessfull";
}
}
$link->close();
?>
这是我的update.php 文件,我将内部的id 显示为textbox 以及id = the text field value 的操作。它正在删除,但最近添加的项目会删除,就像我有 3 个帖子 id 一样(4、5、6)id 先删除 6,然后是 5,然后是 4。我在引导卡中显示数据。但是 post 下的每个删除按钮都会删除最近添加的最新按钮。
【问题讨论】:
-
在删除之前打印
$id的值并检查您是否传递了正确的 ID 值。 -
什么是
$_POST['wow'],它是如何获得的?你真的需要在文本框中显示 id,它可以是隐藏的帖子字段,或者你可以通过 url 传递值 -
我在文本字段中显示帖子的 ID 以确保它是正确的!以及 wow 中文本字段的名称。所以我将其添加为帖子并使其等于 id。但它仍然在删除最近的帖子。第 3 次然后如果我再按第 2 次,即使我想删除第 1 次并从第一张卡中单击删除,它也会删除第 3 次
-
这是我的按钮:( )
标签: php html twitter-bootstrap