如何删除具有复合(多列)主键的php中的记录 [英] How to Delete a Record in php that has composite (multi-column) primary key
问题描述
好,这是要删除的php代码
Ok here is the php code for deletion
<?php
require '../../AppData/database.php'; $id = 0;
if ( !empty($_GET['ActNo'])) {
$id = $_REQUEST['ActNo'];
}
$sec = 0;
if ( !empty($_GET['SectionNo'])) {
$sec = $_REQUEST['SectionNo'];
}
if ( !empty($_POST)) {
// keep track post values
$id = $_POST['ActNo'];
$sec = $_POST['SectionNo'];
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "DELETE FROM section WHERE ActNo = ? AND SectionNo = ?";
$q = $pdo->prepare($sql);
$q->execute(array($id, $sec));
Database::disconnect();
header("Location: index.php");
}
?>
问题: 它不起作用.要么mysql语句不正确,要么它们可能是pdo的问题.也可能与$ _POST以及GET和REQUEST有关.我试图更改sql语句,然后它将删除整个表.更改变量也不起作用.
The problem: It doesn't work. either mysql statement is incorrect or their might be problem with pdo stuff . It could also be something about $_POST and GET and REQUEST things. I tried to change the sql statement then it will delete the whole table. changing the variables doesn't work either.
我希望它一次只删除一个记录. 请有人给我一些建议.
I want it to delete only one record at a time. Please someone give me some suggestion.
推荐答案
1. 检查您的POST:
1. to check your POST:
var_dump $ POST,然后死亡;
var_dump $POST, then die;
2. 检查您的SQL: 强制将正确的值输入您的var $ id ='foo'; $ sec ='bar';
2. to check your SQL: force the correct values into your vars $id = 'foo'; $sec = 'bar';
3. 确保准备好的语句有效,是吗?确实替换为所需的值
3. make sure prepared statement works, is ? really replaced with the desired value(s)
干杯斯蒂芬
这篇关于如何删除具有复合(多列)主键的php中的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!