gpt4 book ai didi

PHP表单提交if else语句

转载 作者:行者123 更新时间:2023-11-29 20:36:03 24 4
gpt4 key购买 nike

我有一个按钮,单击它即可切换我的数据。当页面加载时,我希望它加载所有"new"项目。页面加载时会加载"new"项目,但是当我提交表单以“使用”或“过时”时,它仍然会附加"new"项目。我是 php 新手。谢谢!

 <form action='' method='POST'>
<input type='submit' name='New' value="New"/>
<input type='submit' name='Used' value="Used"/>
<input type='submit' name='Outdated' value="Outdated" />
</form>

这是 php。

    if(isset($_POST['New'])){
$sql = "SELECT name FROM table_all_items WHERE name LIKE '%New%' ";
include '/../includes/product-layout.php';
}

if(isset($_POST['Used'])){
$sql = "SELECT name FROM table_all_items WHERE name LIKE '%Used%' ";
include '/../includes/product-layout.php';
}

if(isset($_POST['Outdated'])){
$sql = "SELECT name FROM table_all_items WHERE name LIKE '%Outdated%' ";
include '/../includes/product-layout.php';
}

else {
$sql = "SELECT name FROM table_all_items WHERE name LIKE '%New%' ";
include '/../includes/product-layout.php';
}

最佳答案

您以错误的方式使用 if-else 条件,您应该将所有这些条件更改为:

if(isset($_POST['New'])){
$sql = "SELECT name FROM table_all_items WHERE name LIKE '%New%' ";
include '/../includes/product-layout.php';
}

else if(isset($_POST['Used'])){
$sql = "SELECT name FROM table_all_items WHERE name LIKE '%Used%' ";
include '/../includes/product-layout.php';
}

else if(isset($_POST['Outdated'])){
$sql = "SELECT name FROM table_all_items WHERE name LIKE '%Outdated%' ";
include '/../includes/product-layout.php';
}

else {
$sql = "SELECT name FROM table_all_items WHERE name LIKE '%New%' ";
include '/../includes/product-layout.php';
}

现在试试这个,只有一个条件有效。

关于PHP表单提交if else语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38806539/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com