我有以下代码->
html5代码块:
<div class="col-md-8 blogger-right-container">
<form action="blogger_account.php" method="post" role="form" enctype="multipart/form-data">
<div class="form-group">
<h2>Blog Title</h2>
<input type="text" class="form-control" name="blog_title" placeholder="Enter title for your blog.">
</div>
<div class="form-group">
<h2>Blog Content</h2>
<textarea name="blog_content" class="form-control" cols="30" rows="10" placeholder="Enter the content here."></textarea>
</div>
<div class="form-group" style="text-align: center;">
<input type="submit" class="btn btn-success btn-lg" name="add" value="Insert">
</div>
</form>
</div> <!-- blogger right container -->
php代码块: `
if(isset($_POST['add'])){
$blogger = $_SESSION['blogger_email'];
$blog_title = $_POST['blog_title'];
$blog_content = $_POST['blog_content'];
$insert_blog = "insert into blogs (blogger_email,blog_title,blog_content) values ('$blogger',$blog_title','$blog_content')";
$run_blog = mysqli_query($con,$insert_blog);
if($run_blog){
echo "<script>alert('Blog inserted.')</script>";
echo "<script>window.open('blogger_account.php','_self')</script>";
}
}`
php 代码块没有在 blogs 表中插入数据。这些列的顺序是正确的,但我仍然试图改变顺序,但没有成功。 谁能告诉我我的代码有什么问题。
最佳答案
请提及您收到的错误。
为了显示详细的 php 错误,导航到“How to get useful error messages in PHP?”
php 中的 MySQL 错误可以这样抛出 --> PHP MySQL error handling
关于javascript - 无法使用php在表中插入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44044724/