2018-11-17 14:43:50 +01:00
|
|
|
<?php
|
|
|
|
if( !isset( $_SESSION ) ) session_start();
|
|
|
|
include "../settings/db_connect.php";
|
|
|
|
$title = $_POST["title"];
|
|
|
|
$meta_desc = $_POST["meta_desc"];
|
|
|
|
$text = $_POST["post_text"];
|
|
|
|
$userlogin=$_SESSION['user'];
|
2018-12-17 11:54:35 +01:00
|
|
|
$avatar_path = $mysqli->real_escape_string('../blog-post/img/post/'.$_FILES['avatar']['name']);
|
2018-11-17 14:43:50 +01:00
|
|
|
$query="SELECT user_id FROM user WHERE username='$userlogin'";
|
|
|
|
if ($result=mysqli_query($mysqli,$query)){
|
|
|
|
while ($row=mysqli_fetch_row($result)){
|
|
|
|
$userid=$row[0];
|
|
|
|
}
|
|
|
|
}
|
2018-12-17 11:54:35 +01:00
|
|
|
if (preg_match("!image!", $_FILES['avatar']['type'])){
|
|
|
|
if(copy($_FILES['avatar']['tmp_name'], $avatar_path)){
|
|
|
|
$sql = $mysqli->prepare("INSERT INTO post VALUES (NULL,?, ?, ?, ?, ?,NOW(),NOW());");
|
|
|
|
if ($sql){
|
|
|
|
$sql->bind_param("issss",$userid,$title,$meta_desc,$text,$avatar_path);
|
|
|
|
$sql->execute();
|
|
|
|
$sql->close();
|
|
|
|
}
|
|
|
|
else echo "ERROR";
|
|
|
|
}
|
2018-11-17 14:43:50 +01:00
|
|
|
}
|
|
|
|
$mysqli->close();
|
2018-12-17 11:54:35 +01:00
|
|
|
header('Location: index.php');
|
2018-11-17 14:43:50 +01:00
|
|
|
?>
|