出现未定义索引错误
我的 php 非常“弱”,所以我遇到了麻烦 -
<?php
include_once "../scripts/connect_to_mysql.php";
$title = $_POST['title'];
$desc = $_POST['description'];
$query = mysql_query("UPDATE images SET title='$title', description='$desc'") or die (mysql_error());
echo 'Operation Completed Successfully! <br /><br /><a href="index.php">Click Here</a>';
exit();
?>
未定义的索引错误是第 9 行的 description
,即 $desc = $_POST['description'];
并且“描述”在数据库中的拼写也是正确的。
my php is very "weak" so I am having trouble with this -
<?php
include_once "../scripts/connect_to_mysql.php";
$title = $_POST['title'];
$desc = $_POST['description'];
$query = mysql_query("UPDATE images SET title='$title', description='$desc'") or die (mysql_error());
echo 'Operation Completed Successfully! <br /><br /><a href="index.php">Click Here</a>';
exit();
?>
The undefined index error is description
on line 9 which is $desc = $_POST['description'];
and "description" is in the database spelling is also right.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的表单需要将此信息发送到 php 文件。看来您的表单中只有
title
而没有description
。您应该发布您的表格以获得更好的帮助。您应该始终对 SQL 查询中使用的数据进行转义。
Your form needs to send this information to the php file. It seems as you only have
title
in your form and notdescription
. You should post your form for better help.You should always escape your data which you are using in SQL queries.
显然,
$_POST
数组中不存在description
字段,因此索引description
不指向任何内容。var_dump($_POST);
打印什么?另外,这是内部系统吗?如果没有,您应该阅读 SQL 注入。
Apparently, a
description
field is not present in the$_POST
array, thus indexdescription
does not point to anything.What does
var_dump($_POST);
print?Also, is this an internal system? If not, you should read up on SQL injections.
$_POST
数组中没有索引为description
的元素。在该行之前尝试
var_dump($_POST);
来检查数组。 (或者,如果某些信息被剪切,请使用print_r($_POST);
There is no element with index
description
in the$_POST
array.Try
var_dump($_POST);
before that line to examine the array. (Alternatively, if some information is cut, useprint_r($_POST);
尝试这样做:
这不会修复它,但它将有助于确定 $_POST['description'] 是否存在。另外,
$_POST['description']
的来源是什么?它是否设置在../scripts/connect_to_mysql.php
?如何?除非执行更复杂的任务(即 AJAX),POST 变量通常通过提交表单来设置 - 您的代码是在表单提交后加载页面之后出现的吗?如果没有,您可能错误地使用了 _POST 变量...
如果
$_POST['description']
在../scripts/connect_to_mysql.php
代码中的某处设置,并通过包含您希望检索其值的文件(您可能会做错事情),您能否提供有关$_POST['description']
来源的信息?Try doing:
This wont fix it but it will help determing whether $_POST['description'] exists.. Also, what is the source of
$_POST['description']
?, is it set in../scripts/connect_to_mysql.php
? How?Unless performing more complex tasks (i.e. AJAX), POST variables are typically set by submitting a form- does your code come after the page is loaded following a form submission? If not, you may be incorrectly using _POST variables...
If
$_POST['description']
is set somewhere in the code of../scripts/connect_to_mysql.php
, and by including the file you wish to then retrieve its value- you may be going about things wrongly- can you provide information about the origin of$_POST['description']
?