检查textbox是否为空会返回空,即使我已经在PHP/HTML上输入
这是我的html中的表单检查textbox是否为空会返回空,即使我已经在PHP/HTML上输入,php,html,Php,Html,这是我的html中的表单 <form action="Belo_Connect2.php" method="POST"> <center> Name:<input type="text" name="namefordelete"> <p> //button that submits to php file <button><a
<form action="Belo_Connect2.php" method="POST">
<center>
Name:<input type="text" name="namefordelete">
<p> //button that submits to php file
<button><a href="Belo_Connect2.php" target="_self" style="text-decoration: none" method="POST">DELETE</a></button>
</p>
</center>
姓名:
//提交到php文件的按钮
下面是我的php文件,它返回Name为空,但在本地主机上运行它时,我肯定会输入文本。你们能帮我找出我的错误吗?非常感谢你。请注意,如果我在这里正确删除内容。再次感谢你
$name = filter_input(INPUT_POST,'namefordelete');
if(!empty($name)){
$host = "localhost";
$dbusername = "root";
$dbpassword = "";
$dbname = "studentInfoDB";
$conn = new mysqli($host, $dbusername, $dbpassword, $dbname);
if(mysqli_connect_error()){
die('Connect Error('.mysqli_connect_errno().')'.mysqli_connect_error());
}
//my delete query
else{
$sql = "DELETE FROM studentTbl WHERE Name = '$name'";
if($conn->query($sql)){
echo "One record Deleted!";
}
else{
echo "Error:".$sql."<br>".$conn->error;
}
$conn -> close();
}
}
//this always return even I have an input on my input box from html file name=namefordelete
else{
echo "Name should not be Empty";
die();
}
?>
$name=filter_input(input_POST,'namefordelete');
如果(!空($name)){
$host=“localhost”;
$dbusername=“root”;
$dbpassword=“”;
$dbname=“studentInfoDB”;
$conn=newmysqli($host、$dbusername、$dbpassword、$dbname);
if(mysqli\u connect\u error()){
die('Connect Error('.mysqli_Connect_errno())'。mysqli_Connect_Error());
}
//我的删除查询
否则{
$sql=“从studentTbl中删除,其中Name='$Name';
如果($conn->query($sql)){
echo“删除一条记录!”;
}
否则{
echo“Error:”.$sql.“
”$conn->Error;
}
$conn->close();
}
}
//即使输入框中有来自html file name=namefordelete的输入,也会返回该值
否则{
echo“名称不应为空”;
模具();
}
?>
如果您通过[超链接]直接链接到php屏幕,它将不会在namefordelete输入框中提交数据
因此,请尝试修改如下:
<form action="Belo_Connect2.php" method="POST">
<center>
Name:<input type="text" name="namefordelete">
<input type="submit" value="delete">
</form>
</center>
姓名:
请添加一些适当的代码缩进。当它全部左对齐时,很难跟随流程。
执行var\u转储($\u POST)代码>和过滤器输入()之后,还添加var\u dump($name)查看这些变量实际包含的内容。警告!你完全可以接受攻击!您应该使用参数化的,而不是像这样在查询中直接手动(并且不充分)传递转义的用户数据。@Cid-I完全错过了