因此,出于某种原因,下面的脚本只会在部分代码中执行,无论我是否在提示期间确认。 在没有确认函数标题的情况下更新导致此确认提示的整个函数('refresh:0; url = new_items.php?Patch_No ='。$ patch。'');按照预期工作。
public function save_champions($champion, $noofspellschamp, $patch, $champ_number, $champnospellno, $spellicon, $spelltitle, $change, $description){
include '../DBconnection_patches.php';
$sql ='';
$sql ="INSERT INTO info (Patch_No)
VALUES ('".$patch."')";
$conn->query($sql);
for($i = 1; $i<=$champ_number; $i++){
$sql =
"INSERT INTO champions (Patch_No, Champion)
VALUES (
'".$patch."',
'".$champion[$i]."'
)";
$conn->query($sql);
for($j=1; $j<=$noofspellschamp[$i]; $j++){
switch($spellicon[$i][$j]){
case 'Passive':
$sql = "UPDATE champions SET Passive='".$spelltitle[$i][$j]."' WHERE Champion='".$champion[$i]."' AND Patch_No='".$patch."'";
$conn->query($sql);
break;
case 'Q':
$sql = "UPDATE champions SET Q='".$spelltitle[$i][$j]."' WHERE Champion='".$champion[$i]."' AND Patch_No='".$patch."'";
$conn->query($sql);
break;
case 'W':
$sql = "UPDATE champions SET W='".$spelltitle[$i][$j]."' WHERE Champion='".$champion[$i]."' AND Patch_No='".$patch."'";
$conn->query($sql);
break;
case 'E':
$sql = "UPDATE champions SET E='".$spelltitle[$i][$j]."' WHERE Champion='".$champion[$i]."' AND Patch_No='".$patch."'";
$conn->query($sql);
break;
case 'R':
$sql = "UPDATE champions SET R='".$spelltitle[$i][$j]."' WHERE Champion='".$champion[$i]."' AND Patch_No='".$patch."'";
$conn->query($sql);
break;
}
for($k=1;$k<=$champnospellno[$i][$j];$k++){
$sql = "INSERT INTO spells (Patch_No, Champion, Spell_Change, Spell_Change_Icon, Spell_Type)
VALUES(
'".$patch."',
'".$champion[$i]."',
'".$description[$i][$j][$k]."',
'".$change[$i][$j][$k]."',
'".$spellicon[$i][$j]."'
)";
$conn->query($sql);
}
}
}
echo $conn->error;
if(empty($conn->error)){
echo '<script>
if (confirm("Champions saved. Do you wish to create items page?")== true) {
';
header('refresh: 0; url=new_items.php?Patch_No='.$patch.'');
echo '} else {';
header('refresh: 0; url=../index.php');
echo '}
</script>';
exit;
//
}
}
答案 0 :(得分:1)
问题是你正试图混合你的php和javascript代码。如果要根据用户输入重定向,则应在javascript中执行整个重定向。在PHP中,您正在编写一个标题,告诉页面重定向,然后告诉它重定向到另一个页面。
if(empty($conn->error)){
echo "<script>
if (confirm(\"Champions saved. Do you wish to create items page?\")) {
window.location = \"new_items.php?Patch_No=$patch\";
} else {
window.location = \"../index.php\";
}
</script>";
exit;
}