POST ($coursevalues) からの配列があります。値が数値でない場合は、値をデータベースに追加する必要があります。
ただし、ページが iframe 内にあるため、データが繰り返し送信されているため、追加されている場合はこれを行わないようにしたいと考えています。if true ステートメント内で、値を含む $newcourses 配列を追加しました。次に、if ステートメントに追加しました。配列 $newcourses にない場合は、データベースに追加します。
ただし、データベースに追加しようとすると、MYSQL エラーが発生します。テーブル内での重複は許可されません。
$y = 0;
foreach ($coursevalues as $key => $val) {
// Try to prevent duplicate entry on refresh as value on other form stays
// same - doesn't update to the ID. add or is a variable I made earlier.
if (is_numeric($val) == false && !in_array($val, $newcourses)) {
$newcourses[$y++] = $val;
$tbl = 'tblCourses';
$fieldcourse = 'CourseName';
// This line creates a query that asks the server to create a table,
// with the name and fields described above
$insertQuery = mysql_query("INSERT INTO $tbl ($fieldcourse) VALUES ('$val')")
or die ('Could not insert new course into tblCourses: ' . mysql_error());
$coursevalues[$val] = mysql_insert_id();
}
}
ステートメントを確認して、機能するかどうかを確認できますか? それはPHPにあります。