我在我的服务器中遇到此问题,而在localhost xampp中,它可以很好地解决任何问题。我花了更多的时间来解决这个问题但是徒劳无功。
我已经尝试在phpmyadmin中发布帖子并根据(INSERT INTO posts
(id
,date
,title
,author
复制代码, author_image
,image
,categories
,tags
,post_data
,views
,status
)VALUES(NULL,' $ date',' $ title',' $ author',' $ author_image',' $ image',' $ categories',' $ tags'' $ post_data',' 0',' $ status')&#34 ;; )
<?php
require_once('include/top.php');
if(!isset($_SESSION['username'])){
header('Location: login.php');
}
$session_username = $_SESSION['username'];
$session_author_image = $_SESSION['author_image'];
?>
</head>
<body>
<div id="wrapper">
<!-- NAVBAR STARTING FROM HERE --->
<?php require_once('include/header.php'); ?>
<!-- NAVBAR ENDING HERE -->
<!-- BODY CONTENT STARTING FROM HERE -->
<div class="container-fluid body-section">
<div class="row">
<div class="col-md-3">
<?php require_once('include/sidebar.php'); ?>
</div>
<div class="col-md-9">
<h1><i class="fa fa-plus-square" aria-hidden="true"></i> Add Post <small>Add New Post</small></h1><hr>
<ol class="breadcrumb">
<li><a href="index.php"><i class="fa fa-tachometer" aria-hidden="true"></i> Dashboard</a></li>
<li class="active"><i class="fa fa-plus-square" aria-hidden="true"></i> Add Post</li>
</ol>
<?php
if(isset($_POST['submit'])){
$date = date('Y-m-d h:ia');
$id = $_POST['id'];
$title = mysqli_real_escape_string($con, $_POST['title']);
$categories = $_POST['categories'];
$tags = mysqli_real_escape_string($con, $_POST['tags']);
$status = $_POST['status'];
$session_author_image = $_SESSION['author_image'];
$post_data = mysqli_real_escape_string($con, $_POST['post-data']);
$image = $_FILES['image']['name'];
$tmp_name = $_FILES['image']['tmp_name'];
if(empty($title) or empty($post_data) or empty($tags) or empty($image)){
$error = "All ( * ) Fields Are Required";
}
else{
$insert_query = "INSERT INTO `posts` (`id`, `date`, `title`, `author`, `author_image`, `image`, `categories`, `tags`, `post_data`, `views`, `status`) VALUES ('$id', '$date', '$title', '$author', '$session_author_image', '$image', '$categories', '$tags', '$post_data', '0', '$status')";
if(mysqli_query($con, $insert_query)){
$msg = "Post Has Been Added Successfuly";
$path = "img/$image";
$title = "";
$post_data = "";
$tags = "";
$categories = "";
$status = "";
if(move_uploaded_file($tmp_name, $path)){
copy($path, "../$path");
}
}
else{
$error = "Post Has Not Been Posted";
}
}
}
?>
<div class="row">
<div class="col-xs-12">
<form action="" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label for="title">Title:*</label>
<?php
if(isset($msg)){
echo "<span class='pull-right' style='color:green'>$msg</span>";
}
else if(isset($error)){
echo "<span class='pull-right' style='color:red'>$error</span>";
}
?>
<input class="form-control" value="<?php if(isset($title)){echo $title;}?>" type="text" name="title" placeholder="Post Title.." >
</div>
<div class="form-group">
<a href="media.php" class="btn btn-primary">Media</a>
</div>
<div class="form-group">
<textarea name="post-data" class="form-control" id="textarea" cols="30" rows="10" placeholder="Post Text Here.."><?php if(isset($post_data)){echo $post_data;}?></textarea>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="file">Post Image:*</label>
<input type="file" name="image" >
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="categories">Categories:*</label>
<select class="form-control" name="categories" id="categories">
<?php
$cat_query = "SELECT * FROM categories ORDER BY id DESC";
$cat_run = mysqli_query($con, $cat_query);
if(mysqli_num_rows($cat_run) > 0){
while($cat_row = mysqli_fetch_array($cat_run)){
$cat_name = $cat_row['category'];
echo "<option value='".$cat_name."' ".((isset($categories) and $categories == $cat_name)?"selected":"").">".ucfirst($cat_name)."</option>";
}
}
?>
</select>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="tags">Tags:*</label>
<input value="<?php if(isset($tags)){echo $tags;}?>" class="form-control" type="text" name="tags" placeholder="Tags Separated By Comma e.g tag1, tag2" >
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="status">Status:*</label>
<select class="form-control" name="status" id="status">
<option value="draft" <?php if(isset($status) and $status == 'draft'){echo "selected";}?></optio>Draft</option>
<option value="publish" <?php if(isset($status) and $status == 'publish'){echo "selected";}?>>Publish</option>
</select>
</div>
</div>
<input type="submit" class="btn btn-primary" value="Publish Post" name="submit">
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<?php require_once('include/footer.php');?>