Php 如何将用户输入放入SQL查询
我有一个数据库,我希望用户能够输入输出的内容。i、 ePhp 如何将用户输入放入SQL查询,php,mysql,Php,Mysql,我有一个数据库,我希望用户能够输入输出的内容。i、 e Select from Table where example = user input from box **(input by the user)** 我猜我需要的是一个变量来保存进入语句的值。我知道如何使用脚本从输入框中获取值,但我可以像这样使用它: 从交接中选择*其中hdate=变量。不过,我猜如果可能的话,有人会跟我谈安全问题 <html><body> <input>User input&l
Select from Table where example = user input from box **(input by the user)**
我猜我需要的是一个变量来保存进入语句的值。我知道如何使用脚本从输入框中获取值,但我可以像这样使用它:
从交接中选择*其中hdate=变量。不过,我猜如果可能的话,有人会跟我谈安全问题
<html><body>
<input>User input</input> //That needs to go into statement
<?php
include 'config.php';
$result = mysqli_query($con,"SELECT * FROM handover WHERE hdate = **user input**;");
echo "<table border='1'>
<tr>
<th>hdate</th>
<th>Delay</th>
<th>Health and Safety</th>
<th>Non Vsa</th>
<th>VSA</th>
<th>Dar</th>
<th>Other</th>
<th>Hour</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['hdate'] . "</td>";
echo "<td>" . $row['hdelay'] . "</td>";
echo "<td>" . $row['hs'] . "</td>";
echo "<td>" . $row['nv'] . "</td>";
echo "<td>" . $row['vsa'] . "</td>";
echo "<td>" . $row['dar'] . "</td>";
echo "<td>" . $row['other'] . "</td>";
echo "<td>" . $row['hour'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
用户输入//需要进入语句
欢迎您提供任何帮助,并提供有关最佳语言的建议
问候
Fintan首先,这个问题与javascript和ajax无关。所以你可以删除那些标签 您希望显示/搜索mysql中的数据
$result = mysqli_query($con,"SELECT * FROM handover WHERE hdate = '".$_POST['abc']."' ");
此时,您需要检查hdate列是否有精确的数据作为用户输入($\u POST['abc'])
也别忘了使用
您可以从这里学习常见的mysql模式查询:@charlietfl您可以通过ajax进行查询,但是没有迹象表明要在那里使用它们。flintan想学习mysql模式来搜索数据。如果您想通过ajax进行操作,请尝试以下方法:不反对ajax。:)