2015-11-19 21 views
0

在我的本地服務器中,此腳本正常工作。當我上傳這個腳本時,它不能正常工作。foreach數據庫中沒有更新數據

它只將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'); 
?> 
+0

有沒有一種可能性,即有第126位插入後MySQL錯誤? – SheppardDigital

+0

您可以檢查本地服務器上的最大執行時間和腳本超時是否與您的活動服務器的超時時間相同? –

+0

你需要增加最大執行時間寫'ini_set('max_execution_time',300); ''在頁面頂部 – Saty

回答

0

這可能是你活的服務器上的exammarks表定義包含一個唯一索引不存在本地主機服務器上。如果這是真的,您的某些INSERT操作可能會失敗。

您向我們展示的代碼不檢查錯誤。很明顯,當你的程序處理高價值的數據時(例如學生考試的結果),你應該檢查錯誤。

試試這個:

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

沒有顯示任何錯誤。 –