我想我不能发布超过2个链接,因为我是新手,所以我会把链接放在pastebin上。http://pastebin.com/2kab4LND
基本上,我编写了一个表单来向数据库提交值。这些值是昵称、标题、日期和内容(基本上是他们写东西的地方)不管怎样,几个小时前这一切都很顺利。无论内容值是多少文本,它都会提交到数据库。
第一张图显示数据库按预期工作。
然而,现在,当我尝试使用该表单提交与该表单相同的值时,它将不会出现任何错误。第二张图大致显示了在内容根本不会出现之前,我可以获得多大的内容。其他一切都有效,比如昵称和标题,我想只是内容一旦超过限制就不起作用了。
我没有更改任何代码,所以在向您展示我的mysql表之后,我将展示这一点。
第三张图是我的桌子。我没有改变他们。桌子工作得很好的时候看起来就是那样。
这是我的表格代码。我去掉了一些东西,这样读起来稍微容易一点,但这是最好的。这是以前工作过的代码,我没有做任何更改,所以我不确定是否会有任何错误导致这种情况发生。现在我将向您展示它的连接。对不起,它真的很乱。
<?php
echo "<form id='submit-form' name='submit-form' action='".setDreams($conn)."' method='POST'>
<input type='hidden' name='dreamid' value=''>
<input type='hidden' name='date' value='".date('Y-m-d H:i:s')."'>
<div id='title'>
<textarea type='text' name='dreamtitle' value='title' id='title_textarea' placeholder='Write the title of your dream here. (Max 40 characters)' method='POST' rows='1' style='margin-left: 10px' style='z-index: 1'></textarea>
</div>
<div id='dream_editor'>
<textarea type='text' name='thedream' value='dream' id='dream_textarea' placeholder='Describe your dream here (Must be at least 250 characters)' method='POST' rows='8' style='margin-left: 10px' style='z-index: 1'></textarea>
</div>
<div id='desired_nickname'>
<textarea type='text' method='POST' type='nickname' name='dreamnickname' value='' id='nickname_textarea' placeholder='Write your desired nickname' rows='1' style='margin-left: 10px' style='z-index: 1'></textarea>
</div>
<button id='submitDreamButton' style='margin-bottom: 10px' name='dreamSubmit' type='submit'></button>
<button id='cancelButton' style='margin-bottom: 10px' href='index.php'></button>
</form>";
?>
这是一个在表单外工作的函数。无论如何,正如我已经说过的,这是一段有效的代码,直到我没有更改它之后它才停止工作。我看了很多次,没有发现任何错误。
<?php
function setDreams($conn) {
if (isset($_POST['dreamSubmit'])) {
$uid = $_POST['dreamid'];
$date = $_POST['date'];
$dreamtitle = $_POST['dreamtitle'];
$thedream = $_POST['thedream'];
$nickname = $_POST['dreamnickname'];
$sql = "INSERT INTO dreams (dreamid, nickname, date, content, title) VALUES ('$uid','$nickname','$date','$thedream','$dreamtitle')";
$result = $conn->query($sql);
}
}
这让我很紧张,因为我知道它刚刚起作用,我很困惑为什么现在不起作用。我希望这篇文章不是太难阅读,我希望你能理解这个问题:)
提前感谢
您的action
属性必须为URL格式。
<form id='submit-form' name='submit-form' action='process.php' method='POST'>
<input type='hidden' name='dreamid' value=''>
<input type='hidden' name='date' value='".date('Y-m-d H:i:s')."'>
<div id='title'>
<textarea type='text' name='dreamtitle' value='title' id='title_textarea' placeholder='Write the title of your dream here. (Max 40 characters)' method='POST' rows='1' style='margin-left: 10px' style='z-index: 1'></textarea>
</div>
<div id='dream_editor'>
<textarea type='text' name='thedream' value='dream' id='dream_textarea' placeholder='Describe your dream here (Must be at least 250 characters)' method='POST' rows='8' style='margin-left: 10px' style='z-index: 1'></textarea>
</div>
<div id='desired_nickname'>
<textarea type='text' method='POST' type='nickname' name='dreamnickname' value='' id='nickname_textarea' placeholder='Write your desired nickname' rows='1' style='margin-left: 10px' style='z-index: 1'></textarea>
</div>
<button id='submitDreamButton' style='margin-bottom: 10px' name='dreamSubmit' type='submit'></button>
<!-- Your submit button must have the value attribute otherwise, isset($_POST['dreamSubmit']) means your button doesn't have a value -->
<button id='submitDreamButton' style='margin-bottom: 10px' name='dreamSubmit' value="Submit" type='submit'></button>
<button id='cancelButton' style='margin-bottom: 10px' href='index.php'></button>
</form>
process.php
<?php
if (isset($_POST['dreamSubmit'])) {
setDreams($conn);
}
function setDreams($conn) {
$uid = $_POST['dreamid'];
$date = $_POST['date'];
$dreamtitle = $_POST['dreamtitle'];
$thedream = $_POST['thedream'];
$nickname = $_POST['dreamnickname'];
$sql = "INSERT INTO dreams (dreamid, nickname, date, content, title) VALUES ('$uid','$nickname','$date','$thedream','$dreamtitle')";
$result = $conn->query($sql);
}