<?php
$output = NULL;
if(isset($_POST['submit'])){
$st = $_POST['search'];
//Connect to the Database
$mysqli =NEW mysqli("localhost","root","","exam");
$search = $mysqli->real_escape_string($st);
echo $st;
//Query Database
$result = $mysqli->query("SELECT * FROM users WHERE name = '$search'");
if($result->num_rows > 0){
echo "yes";
}
else{
echo "No RESULT";
}
}
?>
<form>
<input type="TEXT" name="search"/><br>
<input type="SUBMIT" name="submit" value="search"/>
</form>
答案 0 :(得分:2)
您的表单未指定默认为GET的method
,并且您使用的是$_POST
数组。
因此,您需要为其指定“post”方法。
另外,请考虑使用PDO而不是some very important benefits的原始mysqli连接。