我正在开发一个小型的PHP + MySQL应用程序。我遇到了一个问题,其中一个插入语句似乎导致MySQL在每次插入后添加一些额外的空白行。这是我的设置:
我有一个插入函数:
function addFacCertification($facultyID,$month,$year,$completed,$certificatesent,$confirmationtodean,$comments)
{
//echo "$facultyID<br>$month<br>$year<br>$completed<br>$certificatesent<br>$confirmationtodean<br>$comments";
$today = getdate();
$month = $today["mon"];
$date = $today["mday"];
$year = $today["year"];
$curdate = "$year" ."-". "$month" . "-" . "$date";
$sql = mysql_query("INSERT INTO facultycertification (facultyID,cmonth, cyear, completed, certificatesent, confirmationtodean, comments, certifiedon)
VALUES ('$facultyID', '$month', '$year', '$completed', '$certificatesent', '$confirmationtodean','$comments', '$curdate')");
return $sql;
}
函数调用:
$sqlresults = addFacCertification($_POST["facultyID"], $_POST["month"], $_POST["year"], $_POST["completed"], $_POST["csent"],
$_POST["ctodean"], $_POST["comments"]);
问题是,每次运行时 - 我在表格中得到一个额外的行:(见下面第二行)图片在这里:
任何想法为什么?这是表结构:
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
facultyID INT NOT NULL,
cmonth INT NOT NULL,
cyear INT NOT NULL,
completed INT NOT NULL,
certificatesent INT NOT NULL,
confirmationtodean INT NOT NULL,
comments TEXT,
certifiedon DATE,
FOREIGN KEY (facultyID) REFERENCES faculty(id)
答案 0 :(得分:2)
我想你的代码会以某种方式被执行两次。我建议以下(按此顺序)调试问题:
echo
并查看它是否两次回显(即您正在调用该函数两次)tail
运行此网络服务器日志以查看请求是否正在进行两次如果你没有自己设置它,你可能会在db上执行类似MySQL触发器的操作,但我认为这不太可能。