<?php

ob_start();

if (!session_start()) {
    session_start();
}
try {
    $db = new PDO('mysql:host=localhost;dbname=gdhhsxmy_monsoonvibespublica;charset=utf8', 'gdhhsxmy_monsoonvibespublica', 'monsoonvibespublica');
} catch (Exception $e) {
    echo 'Error has Occured';
}




$title       = $_POST['title'];
$description = addslashes($_POST['description']);
$file        = $_FILES['photo'];


$filename  = rand(1, 10000);
$filepath  = $file['tmp_name'];
$fileerror = $file['error'];


$stmt = $db->prepare("insert into author values(null,'$title','$filename','$description')");
$stmt->execute();
$LAST_ID = $db->lastInsertId();


if ($fileerror == 0) {
    $picname = $LAST_ID;
    $stmt    = $db->prepare("Update author set image='$picname' where id=$LAST_ID");
    $stmt->execute();


    $destfile = '../../pic/author/' . $picname;
    //ECHO  $destfile;

    move_uploaded_file($filepath, $destfile);
}

header('location:../author.php');
exit();
