<? include('header.php') ?>
<h2>add books</h2>



<form method="post" action="" enctype="multipart/form-data">

book title : <input type="text" name="booktitle">
<br>
author name : <input type="text" name="authorname">
<br>
categorie:<select name="categorie_id">
<?php
include('connect.php');
$sql=mysql_query("select * from categorie");
while($row=mysql_fetch_array($sql))
{
echo '<option value="'.$row['id'].'">'.$row['title'].'</option>';
}
include('disconnect.php');
?>
</select>

<br>
uplode book : <input type="file" name="book">
<br>
<input type="submit" name="add" value="  add  ">
</form>

<?php
if($_POST['add'])
{
if($_SESSION['user_id'])
{
include('connect.php');
$booktitle=$_POST['booktitle'];
$authorname=$_POST['authorname'];
$categorie_id=$_POST['categorie_id'];
$bookname=time().$_FILES['book']['name'];
//$bookname=str_replace(" ","_",$bookname);
copy($_FILES['book']['tmp_name'],'booksfiles/'.$bookname);
mysql_query("insert into addbook (book_title,categorie_id,author_name,book,date_of_add)
values('$booktitle','$categorie_id','$authorname','$bookname',now())");


echo 'book added sucsefully !';
include('disconnect.php');
}
else
{
echo 'you must sign in too can add book';
}
}

?>