Guest User

Untitled

a guest
Jun 22nd, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. <?php
  2. require('../dbcon.php');
  3.  
  4. if(!empty($_POST))
  5. {
  6. $msg=array();
  7. if(empty($_POST['name']) || empty($_POST['description']) || empty($_POST['publisher'])|| empty($_POST['edition']) || empty($_POST['pages']) || empty($_POST['price']))
  8. {
  9. $msg[]="Please full fill all requirement";
  10. }
  11. if(!(is_numeric($_POST['price'])))
  12. {
  13. $msg[]="Price must be in Numeric Format...";
  14. }
  15. if(!(is_numeric($_POST['pages'])))
  16. {
  17. $msg[]="Page must be in Numeric Format...";
  18. }
  19.  
  20. if(empty($_FILES['img']['name']))
  21. $msg[] = "Please provide a file";
  22.  
  23. if($_FILES['img']['error']>0)
  24. $msg[] = "Error uploading file";
  25.  
  26.  
  27. if(!(strtoupper(substr($_FILES['img']['name'],-4))==".JPG" || strtoupper(substr($_FILES['img']['name'],-5))==".JPEG"|| strtoupper(substr($_FILES['img']['name'],-4))==".GIF"))
  28. $msg[] = "wrong file type";
  29.  
  30. if(file_exists("../upload_image/".$_FILES['img']['name']))
  31. $msg[] = "File already uploaded. Please do not updated with same name";
  32.  
  33. if(empty($_FILES['ebook']['name']))
  34. $msg[] = "Please provide a document file";
  35.  
  36. if($_FILES['ebook']['error']>0)
  37. $msg[] = "Error uploading document file";
  38.  
  39.  
  40. if(!(strtoupper(substr($_FILES['ebook']['name'],-4))==".PDF" || strtoupper(substr($_FILES['ebook']['name'],-4))==".PPT" ||strtoupper(substr($_FILES['ebook']['name'],-5))==".PPTX" || strtoupper(substr($_FILES['ebook']['name'],-4))==".DOC"|| strtoupper(substr($_FILES['ebook']['name'],-4))==".TXT"|| strtoupper(substr($_FILES['ebook']['name'],-5))==".DOCX"))
  41. $msg[] = "wrong document file type";
  42.  
  43. if(file_exists("../upload_ebook/".$_FILES['ebook']['name']))
  44. $msg[] = "Document File already uploaded. Please do not updated with same name";
  45.  
  46. if(!empty($msg))
  47. {
  48. echo '<b>Error:-</b><br>';
  49.  
  50. foreach($msg as $k)
  51. {
  52. echo '<li>'.$k;
  53. }
  54. }
  55. else
  56. {
  57. move_uploaded_file($_FILES['img']['tmp_name'],"../upload_image/".$_FILES['img']['name']);
  58. $b_img = "upload_image/".$_FILES['img']['name'];
  59.  
  60. move_uploaded_file($_FILES['ebook']['tmp_name'],"../upload_ebook/".$_FILES['ebook']['name']);
  61. $b_pdf = "upload_ebook/".$_FILES['ebook']['name'];
  62.  
  63. $b_nm=$_POST['name'];
  64.  
  65. $b_desc=$_POST['description'];
  66. $b_edition=$_POST['edition'];
  67. $b_publisher=$_POST['publisher'];
  68.  
  69. $b_pages=$_POST['pages'];
  70. $b_price=$_POST['price'];
  71.  
  72.  
  73.  
  74.  
  75. $query="insert into book(b_nm,b_desc,b_edition,b_publisher,b_page,b_price,b_img,b_pdf)
  76. values('$b_nm','$b_desc','$b_edition','$b_publisher','$b_pages','$b_price','$b_img','$b_pdf')";
  77.  
  78. $qry= mysqli_query($dbcon,$query) or die($query."Can't Connect to Query...");
  79. if ($qry==TRUE) {
  80. ?>
  81. <script type="text/javascript">
  82. alter('The Book is uploaded successfully, Click OK to upload more books.');
  83. window.open('addbook.php','_self')
  84. </script>
  85. <?php
  86. }
  87.  
  88.  
  89. }
  90. }
  91. else
  92. {
  93. header("location:admindash.php");
  94. }
  95. ?>
Add Comment
Please, Sign In to add comment