【问题标题】:Delete from database doesn't work correctly从数据库中删除无法正常工作
【发布时间】:2016-06-07 06:24:20
【问题描述】:

所以我有多对多的额外表,我想从额外表中删除一行。

CREATE TABLE `person_cars` (
  `person_cars_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `person_id` int(10) NOT NULL,
  `car_id` int(10) NOT NULL,
  PRIMARY KEY (`person_cars_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

这个 PHP 不起作用

    if(isset($_GET['id']) && isset($_GET['person_cars_id'])) {

    $person_id = $_GET['id'];
    $person_cars_id = $_GET['person_cars_id'];
    $person->deleteCarOfPerson($person_cars_id);
    header('location:join.php?id=' + $person_id);
} 

SQL

    public function deleteCarOfPerson($person_cars_id) {
    $sql = ("DELETE FROM person_cars
            WHERE person_cars_id = '{$person_cars_id}'");
    $result = mysql_query($sql, $this->mysql_database->getConnection());
    return $result; 
}

现在删除正在运行,但 header('location:join.php?id=' + $person_id); 无效

    if(isset($_GET['person_cars_id'])) {

    $person_id = $_GET['id'];
    $person_cars_id = $_GET['person_cars_id'];
    $person->deleteCarOfPerson($person_cars_id);
    header('location:join.php?id=' + $person_id);
} 

【问题讨论】:

  • header('Location: join.php?id='.$person_id);

标签: php mysql header delete-row


【解决方案1】:

当您将 PHP 与 Javascript 混合使用时,您的重定向不起作用。

改变

header('location:join.php?id=' + $person_id); 

header('Location: join.php?id='.$person_id);

+在Javascript中用于添加一些东西。

【讨论】:

  • 感谢您的回答。我检查了这个,但我收到了这个错误 * 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以了解在第 1 行的 '' 附近使用正确的语法 * 并且重定向仍然不起作用。
【解决方案2】:

无论何时使用 header 函数,你都应该在 header 重定向后使用 exit。

header("位置:JOIN.PHP"); 退出;

【讨论】:

    猜你喜欢
    • 2020-10-19
    • 2011-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多