我有一个存储区号的会话。我想要做的是遍历每个区号,看看 MySql 数据库中是否有任何记录。如果没有记录,那么我想将该区号插入到另一个表中。
我创建了一个循环来执行此操作,但它没有插入新记录。也许我对 !isset 的使用是错误的?如果我没有意义,这是我的代码:
//Start
//Set Variables.
$today = date("Y-m-d");
$getAreaCodes = $_SESSION['area_code'];
// Start Foreach Loop. For every area code in session, get it's area code from the zip_zip table
foreach($getAreaCodes as $value) {
mysql_select_db($database_localhost, $localhost);
$query_getAC = sprintf("SELECT area_code FROM zip_zip WHERE area_code = $value", GetSQLValueString($colname_getAC, "text"));
$getAC = mysql_query($query_getAC, $localhost) or die(mysql_error());
$row_getAC = mysql_fetch_assoc($getAC);
$totalRows_getAC = mysql_num_rows($getAC);
// If it does NOT exist, insert it into zip_areacodes.
if (!isset($row_getAC)){
$insertSQL = sprintf("INSERT INTO zip_areacodes (area_code, date, type) VALUES (%s, %s, %s)",
GetSQLValueString($value, "text"),
GetSQLValueString($today, "text"),
GetSQLValueString("bad", "text"));
$Result1 = mysql_query($insertSQL, $localhost) or die(mysql_error());
}
}
mysql_free_result($getAC);
//Moving to another page
header("Location: confirm.php");
exit;