出现未定义索引错误

发布于 2024-12-08 21:14:34 字数 520 浏览 0 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

森罗 2024-12-15 21:14:34

您的表单需要将此信息发送到 php 文件。看来您的表单中只有 title 而没有 description。您应该发布您的表格以获得更好的帮助。

<form ...>
  <input type="text" name="description" value="">
  <input type="text" name="title" value="">
</form>

您应该始终对 SQL 查询中使用的数据进行转义。

Your form needs to send this information to the php file. It seems as you only have title in your form and not description. You should post your form for better help.

<form ...>
  <input type="text" name="description" value="">
  <input type="text" name="title" value="">
</form>

You should always escape your data which you are using in SQL queries.

独自唱情﹋歌 2024-12-15 21:14:34

显然,$_POST 数组中不存在 description 字段,因此索引 description 不指向任何内容。

var_dump($_POST); 打印什么?

另外,这是内部系统吗?如果没有,您应该阅读 SQL 注入。

Apparently, a description field is not present in the $_POST array, thus index description 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.

深巷少女 2024-12-15 21:14:34

$_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, use print_r($_POST);

蓝眼泪 2024-12-15 21:14:34

尝试这样做:

if(isset($_POST['description'])){echo "yes";}else{echo "no";}

这不会修复它,但它将有助于确定 $_POST['description'] 是否存在。另外,$_POST['description'] 的来源是什么?它是否设置在../scripts/connect_to_mysql.php?如何?

除非执行更复杂的任务(即 AJAX),POST 变量通常通过提交表单来设置 - 您的代码是在表单提交后加载页面之后出现的吗?如果没有,您可能错误地使用了 _POST 变量...

如果 $_POST['description']../scripts/connect_to_mysql.php 代码中的某处设置,并通过包含您希望检索其值的文件(您可能会做错事情),您能否提供有关 $_POST['description'] 来源的信息?

Try doing:

if(isset($_POST['description'])){echo "yes";}else{echo "no";}

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']?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文