简体   繁体   English

(PHP / MYSQL)插入大值,无超时或错误时,Insert Into将不起作用

[英](PHP/MYSQL) Insert Into won't work when inserting large values, no timeout or errors

I'm working on an AS3 program using flash; 我正在使用Flash开发AS3程序; in the program, you enter your Username and Password and pick a deck of cards to register; 在程序中,输入用户名和密码,然后选择一副卡片进行注册; When the register button is clicked, flash sends the username, password, and a long string from the deck of cards, which can reach over 1 MB long (but at the moment, it's only 1 KB long). 单击注册按钮后,Flash会从卡片组中发送用户名,密码和一个长字符串,该字符串可以超过1 MB长(但目前只有1 KB长)。

To do this, I use the INSERT INTO method. 为此,我使用INSERT INTO方法。 This is my code: 这是我的代码:

<?php 

/*
connect to database
*/

include "connect.php";

/*
create POST vars to receive data from flash
*/

$username = $_POST['username'];
$password = $_POST['password'];

$sdTrunkest = $_POST['sdTrunk'];


$sql = "INSERT INTO users (username, password, Trunk) VALUES ('$username', '$password', '$sdTrunkest')";
mysql_query($sql); 
exit("result_message=Success");
?>

When I run this code while $sdTrunkest is about maybe 100 Bytes long, it runs fine and registers. 当我在$ sdTrunkest大约100字节长的情况下运行此代码时,它可以正常运行并注册。 But when I try running it when $sdTrunkest is about 1 KB, it simply "pretends that it never saw" the INSERT INTO line. 但是,当我尝试在$ sdTrunkest约为1 KB时运行它时,它只是“假装从未见过” INSERT INTO行。 It doesn't give me a timeout error, and even so I tried using ini_set('max_execution_time', 0); 它不会给我超时错误,即使如此,我还是尝试使用ini_set('max_execution_time', 0); , but it didn't change. ,但没有改变。 In fact, it doesn't give me any errors at all. 实际上,它根本不会给我任何错误。 Is INSERT INTO unable to handle long text? INSERT INTO无法处理长文本吗? And is there a way to fix this? 有办法解决这个问题吗?

Thank you in advance ^^ 预先谢谢^^

I found the problem. 我发现了问题。 It had little to do with that mysql_connect error, but I might as well change to mysqli to avoid other errors. 它与mysql_connect错误没有任何关系,但是我还是最好改用mysqli以避免其他错误。 Anyways, the problem was with the string itself; 无论如何,问题出在字符串本身。 Not in its size, but in its contents. 不是大小,而是内容。 One of the cards' names had an apostrophe, which is probably what messed things up. 其中一张卡的名称带有撇号,这很可能使事情搞砸了。 I removed the apostrophe, copied the text and pasted it multiple times to increase the size, and it still worked perfectly. 我删除了撇号,复制了文本并将其粘贴多次以增加大小,但仍然可以正常使用。

I guess the reason why this question is asked so frequently is because the more text you add, the more likely you are to make a mistake. 我猜为什么这么频繁地问这个问题是因为您添加的文字越多,您犯错的可能性就越大。

Thank you very much to everyone who commented ^^ 非常感谢所有发表评论的人^^

Yes, that is typically referred to as sanitizing inputs, and was my first comment. 是的,这通常被称为清理输入,这是我的第一条评论。 There are several ways to sanitize, but the easiest is to understand is to use mysql_real_escape_string ( http://www.php.net/manual/en/function.mysql-real-escape-string.php ) 有几种清理方法,但最容易理解的是使用mysql_real_escape_string( http://www.php.net/manual/zh/function.mysql-real-escape-string.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM