我是phpMyAdmin的新手,请有人帮忙。 我在php中有一个多维数组,我试图将信息插入到我的数据库中,但由于某种原因,信息会重复出现。例如,如果我在我的阵列上只有三个人的信息,数据库将插入5个人重复一些。程序执行的查询多于应有的查询。我不知道这是否与phpMyAdmin或我的PHP代码有关。
require("connect_db.php");
foreach($alumni as $alum){
//firstName and lastName must exist since they are required fields.
$first_name= $alum['firstName'];
$last_name= $alum['lastName'];
//check if the alum has provided a summary.
if (array_key_exists('summary', $alum)){
$summary= $alum['summary'];
}else{
$summary= "No summary available";
}
//check if the alum has provided a headline.
if (array_key_exists('headline', $alum)){
$headline= $alum['headline'];
}else{
$headline= "No headline available";
}
//check if the alum has provided a picture.
if (array_key_exists('pictureUrl', $alum)){
$picture= $alum['pictureUrl'];
}else{
$picture= "No picture available";
}
mysql_query("INSERT INTO profile VALUE('','$first_name','$last_name','$headline','$summary', '$picture')");
//echo $first_name." ". $last_name." ".$headline." ".$summary;
}
mysql_close($link);
表格如下所示:
ID firstname lastname headline summary pictureURL
----------------------------------------------------
1 Jane Smith Student blah blah
-----------------------------------------------------
2 Jane Smith Student blah blah
-------------------------------------------------------
3 John Doe Student blah blah
--------------------------------------------------------
4 Jake Jacobs Student blah blah
-----------------------------------------------------
5 John Doe Student blah blah
------------------------------------------------------