gpt4 book ai didi

php - 如何通过 HTML/PHP 按钮执行 MYSQL 查询

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

大家好,很抱歉,如果我之前的问题不够清楚,但我意识到我真正的问题是我无法传递按钮单击事件来执行 MYSQL 查询。

这是我的按钮,单击该按钮应该执行查询

<form action="invoice.php" method="post">
<input type='submit' name='hehe' />
</form>

然后考虑我已经建立了一个数据库连接,这是我想要实现该技巧的代码,但是当单击“呵呵”按钮时它什么也不做

if(isset($_POST['hehe'])){
$result=mysql_query("
SELECT a.id, a.name, s.descc, a.phone, a.start, a.end, a.price
from wp_app_appointments a
LEFT JOIN wp_app_services s
ON a.id=s.id
WHERE a.status ='confirmed'
order by a.name
");
}

然后我希望它显示在这里。

while($test = mysql_fetch_array($result))

{
if (mysql_num_rows($result)!=0)
{
$id = $test['id'];
echo "<tr align='center'>";
/*echo"<td><font color='black'>" .$test['id']."</font></td>";*/
echo"<td style='width:200px'></td>";
echo"<td style='width:500px'>" .$test['name']."</td>";
echo"<td style='width:200px'>". $test['descc']. "</td>";
echo"<td style='width:200px'>". $test['phone']. "</td>";
echo"<td style='width:200px'>". $test['start']. "</td>";
echo"<td style='width:200px'>". $test['end']. "</td>";
echo"<td style='width:200px'>". $test['price']. "</td>";
echo"<td style='width:200px'> <a href ='print.php.?id=$id' target=_blank >Print</a>";
echo"<td style='width:100px'></td>";
echo "</tr>";

}
}

对之前的问题表示抱歉。

最佳答案

<form action="invoice.php" method="post">
<input type='submit' name='hehe' />
</form>
<?php
if(isset($_POST['hehe']))
{
$result=mysqli_query($con, "
SELECT a.id, a.name, s.descc, a.phone, a.start, a.end, a.price
from wp_app_appointments a
LEFT JOIN wp_app_services s
ON a.id=s.id
WHERE a.status ='confirmed'
order by a.name
");
if(mysqli_num_rows($result)!=0)
{
while($test = mysqli_fetch_array($result))
{
$id = $test['id'];
echo "<tr align='center'>";
echo "<td style='width:200px'></td>";
echo "<td style='width:500px'>".$test['name']."</td>";
echo "<td style='width:200px'>". $test['descc']. "</td>";
echo "<td style='width:200px'>". $test['phone']. "</td>";
echo "<td style='width:200px'>". $test['start']. "</td>";
echo "<td style='width:200px'>". $test['end']. "</td>";
echo "<td style='width:200px'>". $test['price']. "</td>";
echo "<td style='width:200px'> <a href ='print.php.?id=$id' target=_blank >Print</a>";
echo "<td style='width:100px'></td>";
echo "</tr>";
}
}
}

*应保存为“invoice.php”

*数据库连接应该是“mysqli”

例如:

<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db");

// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>

关于php - 如何通过 HTML/PHP 按钮执行 MYSQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25840615/

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