如果我选择水果并混合水果,它会显示lert "You have selected Fruit's favour and Fruit's topping, are you sure?"
但我的代码显示"You have selected chocolate's favour and chocolate's topping, are you sure?"
它不会去别的地方。
if(isset($_POST['submit'])){
if($favour=="Chocolate"and $topping=="Chocolate Chip"){
?>
<script type="text/javascript">
if(window.confirm("You have selected chocolate's favour and chocolate's topping, are you sure?")) { alert("You have apply successfully");window.location="index.php";
} else {
window.location="customization.php";
}
</script>
<?php
}
elseif($favour=="Fruit"and $topping=="Mix Fruit"){
?>
<script type="text/javascript">
if(window.confirm("You have selected Fruit's favour and Fruit's topping, are you sure?")) { alert("You have apply successfully");window.location="index.php";
} else {
window.location="customization.php";
}
</script>
<?php
}
else{
$cakesize=$_POST['cakesize'];
$favour=$_POST['favour'];
$topping=$_POST['topping'];
$color=$_POST['color'];
$cmessage=$_POST['cmessage'];
$cumessage=$_POST['customize_message'];
$date=date("Y-m-d");
?>
<script type="text/javascript">
alert("You have apply successfully");
window.location = "index.php"
</script>
<?php
mysql_query("INSERT INTO customization (cakesize,cfavour,topping, ccolor, cmessage,customizeMessage, C_date, Member_ID,status) VALUES ('$cakesize','$favour' ,'$topping', '$color' ,'$cmessage','$cumessage', '$date', '$uname','pending')");
}
}
答案 0 :(得分:3)
检查条件时,需要使用等于运算符:==
$favour=$_POST['favour'];
$topping=$_POST['topping'];
if($favour=="Chocolate"and $topping=="Chocolate Chip"){
?>
<script type="text/javascript">
if(window.confirm("You have selected chocolate's favour and chocolate's topping, are you sure?")) { alert("You have apply successfully");window.location="index.php";
} else {
window.location="customization.php";
}
</script>
<?php
}
您还需要确保要检查的变量在之前设置为值。我编辑了上面的代码来反映这一点。
答案 1 :(得分:1)
您正在撰写=
而不是==
。