将数据更新到 mysql 不起作用

问题描述:

我试图在从表单获取数据的 php 文件中设置更新功能,但它没有在 phpmysql 中更新它,这是查询,可能是我遗漏了什么.

I am trying to set an update feature in an php file getting data from a form but it's not updating it in the phpmysql, here is the query, may be I am missing something.

 $query="UPDATE controlpanel1 SET ftitle_p1_1 = '$_POST[ftitle_p1_1]'";

好吧,正如每个人都想说的,你不应该这样做,因为它很危险.让我尝试为您提供一个基本示例,说明使用 MySQLi(您想使用 MySQLi 或 PDO)和准备好的语句:

well, as everybody is trying to say, you shouldn't be doing that, because it's dangerous. Let me try to give you a basic sample of what's more or less a more acceptable procedure, with MySQLi (you want to use either MySQLi or PDO) and a prepared statement:

 $query= $MysqliConnection->prepare("UPDATE controlpanel1 SET ftitle_p1_1 = ? WHERE id = ?"); //reason why it's not updating, probably. You have to tell the system where to update. Which row.
 $query->bind_param("si", $title, $id); //string, integral - title and id(?). Just guessing.
 $title = $_POST["title_p1_1"];
 $id = $_GET["I_have_no_idea"]; // or $_POST["I_have_no_idea"];
 $query->execute();
 $query->close();
 $MysqliConnection->close();

或者,参考,比如说,这个页面.请清理数据...即使使用准备好的语句,我也会检查字符串是否有效.我太担心了,你不担心吗?

or, refer to, say, this page. Sanitize data, please...Even with prepared statements I check if the string is valid. I am worrying too much and you're not?