Advertisement
Guest User

GabHelpmePlease2019

a guest
Nov 18th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.53 KB | None | 0 0
  1. <?php
  2.  session_start();
  3.  if($_SESSION['login'] != "OK")
  4.  {
  5.  header('Location: index.php');
  6.  exit();
  7.  }
  8. ?>
  9.  
  10.  
  11.  
  12. <?php require("db.php"); $id =$_REQUEST['BookID'];
  13.  $result = mysql_query("SELECT * FROM books WHERE BookID  = '$id'"); $test = mysql_fetch_array($result); if (!$result)  
  14.         {
  15.         die("Error: Data not found..");
  16.         }
  17.                 $Title=$test['Title'] ;
  18.                 $Author= $test['Author'] ;                  
  19.                 $PublisherName=$test['PublisherName'] ;
  20.                 $CopyrightYear=$test['CopyrightYear'] ;
  21.                 $ISBN=$test['ISBN'] ;
  22.  
  23.     if(isset($_POST['save'])){
  24.        
  25.    
  26.    
  27.     $file = $_FILES['file'];
  28.     //var_dump ($fileName);
  29.     //die();
  30.    
  31.    
  32.     $fileName = $_FILES['file']['name'];
  33.     $fileTmpName = $_FILES['file']['tmp_name'];
  34.     $fileSize = $_FILES['file']['size'];
  35.     $fileError = $_FILES['file']['error'];
  36.     $fileType = $_FILES['file']['type'];
  37.    
  38.    
  39.    
  40.     $fileExt = explode('.', $fileName);
  41.     $fileActualExt = strtolower(end($fileExt));
  42.    
  43.     $allowed = array('jpg', 'jpeg', 'png', 'pdf');
  44.    
  45.    
  46.     if(in_array($fileActualExt, $allowed)){
  47.        
  48.         if($fileError === 0){
  49.             if ($fileSize < 1000000){
  50.                 $fileNameNew = uniqid('',true).".".$fileActualExt;              //sets a unique indentifier related to real time so each file has a unique ID
  51.                 $fileDestination = 'uploads/'.$fileNameNew;
  52.                 move_uploaded_file($fileTmpName,$fileDestination);
  53.                
  54.                
  55.             }else {
  56.                 echo " file too large!";
  57.             }
  58.            
  59.         }else{
  60.             echo " error uploading file!";
  61.         }
  62.        
  63.        
  64.     }else{
  65.         echo " you cannot upload files of this type!";
  66.     }
  67.    
  68.    
  69.     $title_save = $_POST['title'];
  70.     $author_save = $_POST['author'];
  71.     $name_save = $_POST['name'];
  72.     $copy_save = $_POST['copy'];
  73.     $isbn_save = $_POST['isbn'];
  74.     $cover = $fileDestination;
  75.  
  76.     mysql_query("UPDATE books SET Title ='$title_save', Author ='$author_save',
  77.         PublisherName ='$name_save',CopyrightYear ='$copy_save',ISBN ='$isbn_save', cover = '$cover' WHERE BookID = '$id'")
  78.                 or die(mysql_error());  
  79.     echo "Saved!";
  80.      
  81.     header("Location: protected.php");          
  82. }
  83.    
  84. //mysql_close($conn);
  85. ?>
  86. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  87. <html xmlns="http://www.w3.org/1999/xhtml">
  88. <head>
  89. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  90. <title>Untitled Document</title>
  91. </head>
  92.  
  93. <body>
  94. <form action="view.php" method="post">
  95. <table>
  96.     <tr>
  97.         <td>Title:</td>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement