Php 使用TextArea更新SQL-仅使用短字符串更新
我在表单中有一个文本区域。该表单在提交时会将一些信息插入数据库。尽管“newsText”是一个长文本,但我只能插入短字符串。我将用确切的字符数更新这个问题 表格:Php 使用TextArea更新SQL-仅使用短字符串更新,php,html,mysql,Php,Html,Mysql,我在表单中有一个文本区域。该表单在提交时会将一些信息插入数据库。尽管“newsText”是一个长文本,但我只能插入短字符串。我将用确切的字符数更新这个问题 表格: <form id="newsForm" action="<?php echo $uploadHandler ?>" enctype="multipart/form-data" method="post"> <div class="managementNewsTitle">
<form id="newsForm" action="<?php echo $uploadHandler ?>" enctype="multipart/form-data" method="post">
<div class="managementNewsTitle">
Title<br />
<input id="inputNewsTitle" name="inputNewsTitle" type="text"></input>
</div>
<div class="managementNewsTitle">
Image<br />
<input id="inputNewsFile" type="file" name="file" onchange="document.getElementById('inputNewsFilename').value = value;"><br />
Name<br />
<input id="inputNewsFilename" type="text"></input>
</div>
<div class="managementNewsTitle">
Text<br />
<textarea id="inputNewsText" name="inputNewsText"></textarea>
</div>
<input type="hidden" name="givenFileName" id="givenFileName" value="">
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size; ?>">
<input type="hidden" name="newsSubmitValue" id="submitValue" value="no">
<input type="button" id="newsSubmitButton" onclick="newsSubmit()" name="submitButton" value="Save"></input>
</form>
问题已经解决了。这不是字符的数量,而是字符的类型 我在字符串中使用了引号。这使得我的SQL语句过早结束
呜呜。有几件事我应该提一下: 您需要使用以下php函数将输入转义到查询:
mysql\u escape\u string()
另外,您正在使用我不推荐的mysql.*
。您应该考虑使用<代码> MySqLI**<代码>,或者可能是<代码> PDO < /代码>。pdo
的好处是,它将自动转义字符串,因此您不必担心它。这反过来又使事情更加安全,而不会忘记逃避某些事情。(人为错误)
您可以从以下两个方面进行选择:
我建议更改的原因如下:
最好不要在问题标题中添加“已解决”字样。我在这里编辑了它,因为它被认为是一种不好的做法。我想证明这个问题已经解决了,因为我还不能接受我的答案。48小时太多了。你真的需要逃离你的生活inputs@Amal穆拉里,我当然想,但我可以在8小时内接受。要花2天的时间来接受你自己的答案。“戴夫,YUP,这就是解决办法。”斯蒂芬斯图恩,你想让我把它作为你的答案吗?我张贴了答案+你可以考虑的其他信息。
if($_POST['newsSubmitValue'] === "yes") {
$newsTitle = $_POST['inputNewsTitle'];
$newsText = $_POST['inputNewsText'];
$newsImageURL = $_POST['givenFileName'];
mysql_query("INSERT INTO cs_news VALUES (DEFAULT, CURRENT_TIMESTAMP, '".$newsTitle."', '".$newsText."', 'Images/".$newsImageURL."')");
}
if($_POST['newsSubmitValue'] === "yes") {
$newsTitle = mysql_escape_string($_POST['inputNewsTitle']);
$newsText = mysql_escape_string($_POST['inputNewsText']);
$newsImageURL = mysql_escape_string($_POST['givenFileName']);
mysql_query("INSERT INTO cs_news VALUES (DEFAULT, CURRENT_TIMESTAMP, '".$newsTitle."', '".$newsText."', 'Images/".$newsImageURL."')");
}