我无法使用此脚本将数据输入我的MySQL表:
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
session_start();
include '../scripts/test_ses.php';
include 'connection.php';
$date = date("Y-m-d");
/* Set our params */
$id = $_POST['id'];
$status = $_POST['status'];
$active = 1;
$sql = "INSERT INTO TBL_Holiday (Status, Active, DateOfChange) VALUES (?, ?, ?) WHERE idRequest =$id";
$stmt = $conn->prepare($sql);
/* Bind our params */
$stmt->bind_param('iisi', $status, $active, $date, $id);
/* Execute the prepared Statement */
$stmt->execute();
/* Close the statement */
$stmt->close();
?>
变量$ id,$ status的数据是由表单设置有没有办法通过在ajax上的表单页面上提示它来显示脚本的php错误?
答案 0 :(得分:1)
删除用于更新的$id
和WHERE
或删除一行,在您的情况下插入使用以下查询
$sql = "INSERT INTO TBL_Holiday
(Status, Active, DateOfChange) VALUES
(?, ?, ?)";
或者如果您想要更新,则需要使用以下查询
$sql = "UPDATE TBL_Holiday SET
Status= ?,
Active= ?,
DateOfChange= ?
WHERE idRequest = ?";
/* Bind our params */
$stmt->bind_param('iisi', $status, $active, $date, $id);
答案 1 :(得分:1)
通过拥有其ID ..进行更新操作..
$sql = "UPDATE TBL_Holiday SET Status='$status', Active='$active', DateOfChange='$date' WHERE idRequest =$id";
否则..插入..
$sql = "INSERT INTO TBL_Holiday (Status, Active, DateOfChange) VALUES ('$status', '$active', '$date')";
答案 2 :(得分:1)
如果您需要使用条件,则需要使用更新查询,而不是使用插入。所以你的情况会是这样的,
$sql = "UPDATE TBL_Holiday SET Status= ?,Active= ?,DateOfChange=? WHERE idRequest =$id";
答案 3 :(得分:1)
表单上有一个插入语句:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3,...);
where
子句创建与任何其他现有行无关的新记录,即您可以跳过该部分。同时表格上有更新声明:
UPDATE table_name
SET column1=value1, column2=value2,...
WHERE some_column=some_value;
where
子句将更新与某个特定行相关联,以指示要更新哪一行。答案 4 :(得分:0)
这是工作代码:
<?php
/* Set our params */
$date = date("Y-m-d");
$id = $_POST['id'];
$status = $_POST['status'];
$active = 1;
/*Create executed SQL*/
$sql = "UPDATE TBL_Holiday SET
Status= ?,
Active =?,
DateOfChange =?
WHERE idRequest = ?";
/*Prepare SQL connection*/
$stmt = $conn->prepare($sql);
/* Bind our params */
$stmt->bind_param('iisi', $status, $active, $date, $id);
/* Execute the prepared Statement */
$stmt->execute();
/* Close the statement */
$stmt->close();
?>