gpt4 book ai didi

PHP表单处理问题

转载 作者:行者123 更新时间:2023-11-29 12:21:11 27 4
gpt4 key购买 nike

这里是 PHP 新手。过去几天我一直在努力处理这段代码-

我有一个下拉菜单。这些选项来 self 数据库中的表格-

<?php

include('Macintosh HD/Applications/MAMP/htdocs/Deals/processform3.php');

$host = 'localhost';
$username = '';
$password = '';
$database = 'database';

$conn = mysqli_connect($host, $username, $password, $database);

$query = mysqli_query($conn,"SELECT * FROM DealCat");

echo "<form action='processform.php' method='POST'>
<select name = 'dealcat'>/n";

while ($row = mysqli_fetch_assoc($query))
{
echo "<option value='{". $row['dealcat']."}'>" .$row['dealcat']."</option>";
}
echo "</select>\n";

?>
<小时/>

导航菜单在网页上显示良好。但是,我无法处理用户输入。我希望用户单击下拉列表中的选项之一,然后 PHP 运行脚本来获取结果。我知道这可以用 Javascript 来完成,但我不知道,所以尝试只使用 PHP。

<小时/>

这是表单处理脚本-

<?php

$host = 'localhost';
$username = '';
$password = '';
$database = 'database';

$conn = mysqli_connect($host, $username, $password, $database);

$dealcat=$_POST["dealcat"];

$query = "SELECT * FROM Deals WHERE dealcategory=\"{$_POST['$dealcat']"");

$result=mysqli_query($conn,$query) or die ("Couldn’t execute query.");

while($row = mysqli_fetch_assoc($result))
{
echo "<p>" . $row['description'] ."</p>";
echo "<br>";
echo "<a href =' {$row['weblink']}'> {$row['Header']}</a>";
echo "<br>";
echo "<br>";
echo "<a href=\"{$row['weblink']}\"><button >Get Deal</button></a>";
echo "<hr>";
}

?>

有没有一种方法可以让 PHP 根据用户单击下拉选项来显示结果?多谢!

最佳答案

试试这个

<select name="fieldname">    
while ($row = mysqli_fetch_assoc($query))
{
echo "<option value=".$row['dealcat'].">".$row['dealcat']."</option>";
}
</select>

关于PHP表单处理问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28977642/

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