未定义的索引:提交但其工作正常尝试 isset 但失败
Undefined index: submit but its working fine tried isset but fail
我遇到了这个错误谁能帮帮我?
Notice: Undefined index: submit in
D:\xampp\htdocs\testsubject\cntcinfo.php on line 7
这是我的代码:
if($_POST['submit']=='Update')
{
mysqli_query($link," UPDATE usr_profile
SET phone='".$_POST['phone']."',
email='".$_POST['emails']."',
address='".$_POST['address']."',
postcode='".$_POST['postcode']."',
city='".$_POST['city']."';
");
header('Location: '.$_SERVER['HTTP_REFERER']);
exit;
}
我厌倦了使用 isset
但我得到了这个错误:
Fatal error: Cannot use isset() on the result of an expression (you
can use "null !== expression" instead) in
D:\xampp\htdocs\testsubject\cntcinfo.php on line 7
这是我的集
if(isset($_POST['submit']=='Update'))
isset
不用于比较。您可以将其用作
if(isset($_POST['submit']) && $_POST['submit']=='Update')
{
}
Ans 确保您提交类型为
<input type="submit" name="submit" value="Update"/>
您的查询已开放 sql 注入,您可以在更新前使用
$phone=mysqli_real_escape_string ( $link , $_POST['phone'] );
勾选How can I prevent SQL injection in PHP?
使用这个
if(isset($_POST['submit']) && $_POST['submit']=='Update')) {
// Your code here
}
如果要检查是否设置了 POST 值,则需要使用此代码:
if(isset($_POST['submit'])) {
if($_POST['submit'] == 'Update') {
//Do work here
}
}
(或缩短):
if(isset($_POST['submit']) && ($_POST['submit'] == 'Update')) {
//Do work here
}
当您在 isset()
函数中调用 $_POST['submit']=='Update'
时,您要求它检查表达式的结果是否已设置(它无法处理)。
所以你需要像我上面展示的那样嵌套它。
如果您发现您得到的是未定义的索引,请确保您发布的表单已将 submit 设置为其表单元素之一。
并非所有浏览器都会为提交按钮发送值,如果该表单也可用于添加用户,如果是对用户个人资料的更新,请考虑使用复选框进行标记。
你是 SQL 注入攻击的目标,你应该使用准备好的语句来消除 SQL 注入攻击的风险,你还应该检查是否MySQL 曾经 returns 个查询错误。
无论您know/trust您的用户有多好,所有用户提交的数据都需要验证。
我遇到了这个错误谁能帮帮我?
Notice: Undefined index: submit in
D:\xampp\htdocs\testsubject\cntcinfo.php on line 7
这是我的代码:
if($_POST['submit']=='Update')
{
mysqli_query($link," UPDATE usr_profile
SET phone='".$_POST['phone']."',
email='".$_POST['emails']."',
address='".$_POST['address']."',
postcode='".$_POST['postcode']."',
city='".$_POST['city']."';
");
header('Location: '.$_SERVER['HTTP_REFERER']);
exit;
}
我厌倦了使用 isset
但我得到了这个错误:
Fatal error: Cannot use isset() on the result of an expression (you
can use "null !== expression" instead) in
D:\xampp\htdocs\testsubject\cntcinfo.php on line 7
这是我的集
if(isset($_POST['submit']=='Update'))
isset
不用于比较。您可以将其用作
if(isset($_POST['submit']) && $_POST['submit']=='Update')
{
}
Ans 确保您提交类型为
<input type="submit" name="submit" value="Update"/>
您的查询已开放 sql 注入,您可以在更新前使用
$phone=mysqli_real_escape_string ( $link , $_POST['phone'] );
勾选How can I prevent SQL injection in PHP?
使用这个
if(isset($_POST['submit']) && $_POST['submit']=='Update')) {
// Your code here
}
如果要检查是否设置了 POST 值,则需要使用此代码:
if(isset($_POST['submit'])) {
if($_POST['submit'] == 'Update') {
//Do work here
}
}
(或缩短):
if(isset($_POST['submit']) && ($_POST['submit'] == 'Update')) {
//Do work here
}
当您在 isset()
函数中调用 $_POST['submit']=='Update'
时,您要求它检查表达式的结果是否已设置(它无法处理)。
所以你需要像我上面展示的那样嵌套它。
如果您发现您得到的是未定义的索引,请确保您发布的表单已将 submit 设置为其表单元素之一。
并非所有浏览器都会为提交按钮发送值,如果该表单也可用于添加用户,如果是对用户个人资料的更新,请考虑使用复选框进行标记。
你是 SQL 注入攻击的目标,你应该使用准备好的语句来消除 SQL 注入攻击的风险,你还应该检查是否MySQL 曾经 returns 个查询错误。
无论您know/trust您的用户有多好,所有用户提交的数据都需要验证。