我正在尝试使用序列化方法向数据库提交不同的表单输入字段。我在我的textarea上使用tinyMCE。在对此进行研究之后,我现在可以将所有字段提交到除textarea之外的数据库。我不知道为什么它没有被序列化。我应该怎样做我的代码以获取textarea内容到数据库?我的代码如下所示使用序列化方法提交tinyMCE textarea到数据库
表
<form id="myForm" method="post" action="myPage.php">
<textarea class="tinymce" name="texteditor" id="texteditor"></textarea>
<input type="checkbox"name="get_value[]" value="A">
<input type="checkbox"name="get_value[]" value="B">
<input type="checkbox"name="get_value[]" value="C">
<input type="checkbox"name="get_value[]" value="D">
<select name="category" class="form-control" required>
<option>one</option>
<option>two</option>
</select>
<input name="points" type="text" class="form-control" />
<input name="random" type="radio" value="no" /> No <br>
<input name="random" type="radio" value="yes" /> Yes
<button id="sub" name="upload"><b>Submit</b></button>
</form>
Java脚本
$("#sub").click(function() {
$.post($("#myForm").attr("action"), $("#myForm").serialize(), function(info){ $("#result").html(info); });
clearInput();
});
$("#myForm").submit(function() {
return false;
});
function clearInput() {
$("#myForm").each(function() {
$(this).val('');
});
}
PHP
if(!empty($_POST["get_value"])){
foreach($_POST["get_value"] as $checkbox){
}
$question = $_POST['texteditor'];
$random = $_POST['random'];
$category = $_POST['category'];
$points = $_POST['points'];
$insert_question = "insert into questions (question,checkbox,random,category,points) values ('$question','$checkbox','$random','$category','$points')";
$run_question = mysqli_query($con, $insert_question);
if($insert_question){
echo "Question set successfully";
}
else {
echo "failed";
}
}
else{
echo "<script>alert('Please select at least one option!')</script>";
}
那么最新情况呢? fyi,如果你有任何值的话,你的代码就会中断,因为它对SQL注入是开放的。 –
你也应该检查'if($ run_question){'not'if($ insert_question){',这就是为什么你在插入时得到误报。 –
对我无效 – Oponjous