我尝试将Ckeditor用于项目。现在可以将
<div class="form-group">
<label for="exampleInputEmail1">Name</label>
<input type="text" name ="text" class="form-control" id="name" placeholder="Name">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Editor</label>
<textarea name ="text" class="form-control" id="text" rows="3" placeholder="Textarea"></textarea>
</div>
<input type="submit" class="btn btn-primary" name="submit" value ="Submit">
</form>
这是PHP:
<?php
if (isset($_POST['submit']))
{
$text=$_POST['text'];
$name=$_POST['name'];
$con=mysqli_connect('localhost','root','','ckeditor') or die(ERROR);
$query=mysqli_query($con,"INSERT INTO content(content,author) VALUES ('$text','$name')");
if($query==1)
{
echo "<script>
window.location.href='./ask_question.php';
alert('Success');
</script>";
exit;
}
else
{
echo'<script>alert("Failed To Insert")</script>';
}
}
?>
答案 0 :(得分:0)
这是因为您在两个元素中都复制了name
属性("text"
)。提交表单时,使用name
代替id
。
稍作修改就足够了:
<div class="form-group">
<label for="exampleInputEmail1">Name</label>
<input type="text" name="name" class="form-control" id="name" placeholder="Name">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Editor</label>
<textarea name ="text" class="form-control" id="text" rows="3" placeholder="Textarea"></textarea>
</div>
<input type="submit" class="btn btn-primary" name="submit" value ="Submit">
</form>