这是我将近一周的问题,我无法解决。
设想:
在我保存数据之前,会出现一条确认消息,说... Station is full. do you want to continue saving?
...然后当我尝试取消它时,它仍在保存数据..
按取消按钮将不再保存....
假设我有一个建筑物名称:Star 1 和 Star 2 ......
" Star 1"和"Star 2"将是$bldg的值 ..那么 STAR 1的总持续时间是 08:00:00 [这已经满了],那么STAR 2 的总持续时间是 00:00:00 [数据库中尚不存在]
这是我的代码:
if (isset($_GET['js_varOK']))
$cancel = $_GET['js_varOK'];
else $cancel = "not";
if($cancel != "yes")
{
for($i=0; $i<sizeof($bldg);$i++)
{
if($cancel != "yes")
{
$result = mysql_query("SELECT * FROM tbldata WHERE fldNetname = '".$network."' AND fldBldgName = '".$bldg[$i]."' AND fldWeek = '".$week."' AND fldMonth = '".$month."' AND fldYear ='".$year."' ORDER BY id desc");
if(mysql_num_rows($result)==0)
{
$totalduration = "";
$seconds = 0;
$minutes = 0;
$computeSecMin = $seconds * $minutes;
$subSecMin = $computeSecMin + $duration;
$getMin = floor($subSecMin/60);
$getSec = $subSecMin%60;
$totalduration = $getMin .":". $getSec;
$query2 = "INSERT INTO tbldata(fldNetname,fldBldgName,fldPlaylist,fldMonth,fldWeek,fldYear,fldDuration,fldFrom,fldTo,fldTotalDuration,fldTimestamp,fldStatus, fldUser) VALUES ('".$network."','".$bldg[$i]."','".$AdName."','".$month."','".$week."','".$year."','".$duration."','".$from."','".$to."', '".$totalduration."','".$date."','".$status."',(SELECT fldid from tblmembers where fldUsername= '".$_SESSION['user']."'))";
mysql_query($query2) or die (mysql_error());
echo "<script type='text/javascript'>\n";
echo "alert('Data have been saved first!');\n";
echo "</script>";
}
else
{
while ($row = mysql_fetch_array($result))
{
if($network == "Mass and Mobile" && $row[fldTotalDuration] == "08:00:00" && $duration >= "0 s")
{?><?php
if(sizeof($bldg) == 1)
{
echo "<script type='text/javascript'>\n";
echo "alert('$bldg[$i] station is already full.');\n";
echo "window.location='booking_content.php'";
echo "</script>";
}
else
{ ?>
<script>
var myVar = "station is already full. Do you want to save the other networks?";
var js_varOK;
var bldg;
var network;
if (confirm(myVar))
{
js_varOK = "no";
bldg = "<?php echo $bldg?>";
network= "<?php echo $network?>";
window.location = "?js_varOK=" + js_varOK + "&bldg="+bldg + "&network="+network;
} else
{
js_varOK = "yes";
window.location = "?js_varOK=" + js_varOK;
}
</script>
<?php
}
}
}
}
else
{
//do noothing
}
因此,当我点击取消时,它只会转到else of do nothing
...但它仍在保存..
根据我的理解... STAR 1 将是第一个读取 for 循环的程序,然后它会转到"if($network == "Mass and Mobile" && $row[fldTotalDuration] == "08:00:00" && $duration >= "0 s")"
然后会出现一条弹出消息然后我将单击取消按钮然后值$cancel
已经是“是”,那么 STAR 2 已经保存在我的数据库中,这应该是在单击取消时停止程序以保存它....
谢谢..