PDO 插入不向数据库添加记录 table
PDO insert not adding records to database table
出于某种原因,第一个 SQL 有效(UPDATE),但第二个 INSERT 部分什么也不做,也没有将任何内容放入我刚刚创建的新点 table 中。 Points table 很简单,只有这些列:ID、SID、WID、PID。知道为什么没有数据会填充插入的 it/no 行吗?
if(isset($_POST ['yes'])){
// Get values from form
$yes_WID = $_POST['yes'];
$yesupdate = "UPDATE writing SET approved = :approved, position = :position
WHERE WID = :WID";
$stmt2 = $dbh->prepare($yesupdate);
$stmt2->bindParam(':WID', $yes_WID, PDO::PARAM_INT);
$stmt2->bindParam(':approved', $e = Y, PDO::PARAM_STR);
$stmt2->bindParam(':position', $row2[0]['position'], PDO::PARAM_INT);
$stmt2->execute();
$storyauthor = $row[0]['stories.ID'];
$contpoint = 3;
$contauthor = $row2[0]['writing.ID'];
$yesupdate2 = "INSERT INTO points(ID,
SID,
WID,
PID) VALUES(
:ID,
:SID,
:WID,
:PID)";
$stmt9 = $dbh->prepare($yesupdate2);
$stmt9->bindParam(':ID', $contauthor, PDO::PARAM_INT);
$stmt9->bindParam(':SID', $the_SID, PDO::PARAM_INT);
$stmt9->bindParam(':WID', $yes_WID, PDO::PARAM_INT);
$stmt9->bindParam(':PID', $contpoint, PDO::PARAM_INT);
$stmt9->execute();
第一个语句 $e = Y,
中有错误。 Y
必须定义为常量,否则必须将其放在引号中。 'Y'
也足够了。
对于第二个插入语句我们只能猜测,因为无法知道$row
和$row2
中的内容。要进一步调试,请在 $stmt9->execute();
:
之前添加此行
echo "$contauthor, $the_SID, $yes_WID, $contpoint";
检查它是否显示预期值。可能其中之一未定义,而 points
中的列不允许为空。
出于某种原因,第一个 SQL 有效(UPDATE),但第二个 INSERT 部分什么也不做,也没有将任何内容放入我刚刚创建的新点 table 中。 Points table 很简单,只有这些列:ID、SID、WID、PID。知道为什么没有数据会填充插入的 it/no 行吗?
if(isset($_POST ['yes'])){
// Get values from form
$yes_WID = $_POST['yes'];
$yesupdate = "UPDATE writing SET approved = :approved, position = :position
WHERE WID = :WID";
$stmt2 = $dbh->prepare($yesupdate);
$stmt2->bindParam(':WID', $yes_WID, PDO::PARAM_INT);
$stmt2->bindParam(':approved', $e = Y, PDO::PARAM_STR);
$stmt2->bindParam(':position', $row2[0]['position'], PDO::PARAM_INT);
$stmt2->execute();
$storyauthor = $row[0]['stories.ID'];
$contpoint = 3;
$contauthor = $row2[0]['writing.ID'];
$yesupdate2 = "INSERT INTO points(ID,
SID,
WID,
PID) VALUES(
:ID,
:SID,
:WID,
:PID)";
$stmt9 = $dbh->prepare($yesupdate2);
$stmt9->bindParam(':ID', $contauthor, PDO::PARAM_INT);
$stmt9->bindParam(':SID', $the_SID, PDO::PARAM_INT);
$stmt9->bindParam(':WID', $yes_WID, PDO::PARAM_INT);
$stmt9->bindParam(':PID', $contpoint, PDO::PARAM_INT);
$stmt9->execute();
第一个语句 $e = Y,
中有错误。 Y
必须定义为常量,否则必须将其放在引号中。 'Y'
也足够了。
对于第二个插入语句我们只能猜测,因为无法知道$row
和$row2
中的内容。要进一步调试,请在 $stmt9->execute();
:
echo "$contauthor, $the_SID, $yes_WID, $contpoint";
检查它是否显示预期值。可能其中之一未定义,而 points
中的列不允许为空。