gpt4 book ai didi

php - foreach 数据库中的数据未更新

转载 作者:行者123 更新时间:2023-11-29 21:49:23 25 4
gpt4 key购买 nike

在我的本地服务器中,该脚本运行良好。当我实时上传此脚本时,它无法正常工作。

它只向数据库插入 126 行数据,但我需要一次至少上传 500 行。

<?php
include 'database-config.php';
foreach($_POST['classroll'] as $row=>$classroll)
{
$sclassroll = $classroll;
$mark = $_POST['mark'][$row];
$type = $_POST['rtype'];
$session = $_POST['rsession'];
$department = $_POST['rdepartment'];
$examtype = $_POST['rextype'];
$examyear = $_POST['rexyear'];
$examsubject = $_POST['rexmarksubject'];

$stmt = $dbh->prepare("INSERT INTO exammarks(studnettype, studentsession, studentdepartment, studentclassroll, examtype, examyear, examsubjec, exammarks) VALUES (:studnettype, :studentsession, :studentdepartment, :studentclassroll, :examtype, :examyear, :examsubjec, :exammarks)");

$stmt->bindParam('studnettype', $type);
$stmt->bindParam('studentsession', $session);
$stmt->bindParam('studentdepartment', $department);
$stmt->bindParam('studentclassroll', $sclassroll);
$stmt->bindParam('examtype', $examtype);
$stmt->bindParam('examyear', $examyear);
$stmt->bindParam('examsubjec', $examsubject);
$stmt->bindParam('exammarks', $mark);


$stmt->execute();
}
header('Location: ../home.php');
?>

最佳答案

实时服务器上的 exammarks 表定义可能包含本地主机服务器上不存在的唯一索引。如果确实如此,您的某些 INSERT 操作可能会失败。

您向我们展示的代码不会检查错误。显然,当您的程序处理高值(value)数据(例如学生考试结果)时,您应该检查错误。

试试这个:

if( !$stmt->execute()) {
print_r( $arr = $stmt->errorInfo() );
}
else {
/* INSERT statement completed correctly */
}

关于php - foreach 数据库中的数据未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33802669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com