gpt4 book ai didi

php - 如何在php函数中使用表单值?

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

我是 php 的新手。我使用 php 编写了自动完成文本框,并且我有一个提交按钮。我还没有给出表单操作。

这是我用于自动完成文本框的 HTML 表单代码。这个自动完成文本框选择值

<form  method="post" autocomplete="off">
<p>
<b>Theater Name</b> <label>:</label>
<input type="text" name="theater" id="theater" />
</p>
<input type="submit" value="Submit" />
</form>

我有另一个 php 函数,它根据 where 子句检索值。在 where 语句中,我想使用从表单中选择的值。

例如:从 theater_name ="form value"的剧院中选择地址

如何在php函数中使用表单值?谁能帮帮我?

 <?php
$con = mysql_connect("localhost","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("theaterdb", $con);

$result = mysql_query("SELECT * FROM theter
WHERE theater_name="<!-- This could be value that we get after clicking submit button-->);

while($row = mysql_fetch_array($result))
{
echo $row['thearer_name'];
echo "<br />";
}
?>

提前致谢......

最佳答案

您可以通过 $_POST['theater']$_POST 获取值。

注意,你不应该直接在sql中使用这个值,你需要将它转义以防止sql注入(inject)。

$theater = mysql_escape_string($_POST['theater']);
$result = mysql_query("SELECT * FROM theter WHERE theater_name='$theater'";

最后,你可以看看PDO , 这是对旧的 mysql_* 函数的建议。

关于php - 如何在php函数中使用表单值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12455351/

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