将数据更新到 mysql 不起作用 [英] Updating data into mysql not working

查看:34
本文介绍了将数据更新到 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?

这篇关于将数据更新到 mysql 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆