尽管显示一切正常,但数据未保存在localhost或我的文件夹中

时间:2019-06-02 13:57:02

标签: php prepared-statement

当用户尝试发布内容时,我正在运行此代码,尽管它显示发布内容没有问题,但没有数据保存在本地主机或我的文件夹中 我检查了任何类型的错误,目前在控制台页面或任何地方均未显示任何错误,它使我在标题中成功发布了消息,但什么也没保存。

session_start();
if (isset($_POST['submitPost'])){
require '../loginSite/databaseCon.php';
$newFileName=$_POST['postName'];
if(empty($newFileName)){
$newFileName="GalleryPic";
}else{
$newFileName=strtolower(str_replace(" ", "-", $newFileName));
}
$imageTitle=mysqli_real_escape_string($conn,$_POST['postTitle']);
$imageDesc=mysqli_real_escape_string($conn,$_POST['postDesc']);
$file = $_FILES["postImage"];
if(!empty($imageTitle)&&!empty($imageDesc)){
$fileName=$file['name'];
$fileType=$file['type'];
$fileTempName=$file['temp_name'];
$fileError=$file['error'];
$fileSize=$file['size'];
$fileExt = explode(".",$fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array("jpeg","jpg","gif","png");
if(in_array($fileActualExt, $allowed)){
if($fileError===0){
if($fileSize<2000000){
$imageFullName = 
$newFileName.".".uniqid("",true).".".$fileActualExt;
$fileDestination = "PostPhotos/".$imageFullName;
$sql = "SELECT * FROM posts";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql)){
header("Location:Main.php?SQL1-error");
exit();
}else{
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$rowCount = mysqli_num_rows($result);
$setImageOrder = $rowCount+1;
$userUsername = $_SESSION['UserID'];
$userId = "SELECT userId FROM users WHERE 
userUsername='.$userUsername.';";
$sql = "INSERT INTO posts (postTitle, postDesk, postImageFile, 
orderGallery, userId)
VALUES (?,?,?,?,?);";
if(!mysqli_stmt_prepare($stmt, $sql)){
header("Location:Main.php?SQL2-error");
exit();
}else{
mysqli_stmt_bind_param($stmt, "ssssi", $imageTitle,$imageDesc,
$imageFullName, $setImageOrder, $userId);
mysqli_stmt_execute($stmt);
move_uploaded_file($fileTempName, $fileDestination);
header("Location:Main.php?Succesfully-Posted");
exit();
}
}

0 个答案:

没有答案