2017-04-12 73 views
0

請幫助我通過下面的代碼來查看哪裏出現錯誤,因爲代碼在本地系統上工作,但在服務器上工作不正常。它將圖像移動到文件夾,但數據不會移動到數據庫。我已經檢查並檢查過,但不能真正把我的手放在錯誤上,我很快會很感激某種幫助。謝謝。php腳本在系統上本地工作,但不在服務器上

<?php 


include_once("../php/db_connection.php"); 
include_once("php/admin_session.php"); 

?> 
<?php 
// ADD NEW PROPERTY 
$error_msg = ''; 
if(isset($_POST['title'])){ 
$title = $_POST['title']; 
$names = $_POST['name']; 
$description = $_POST['description']; 
$price = $_POST['price']; 
$category = $_POST['category']; 
$location = $_POST['location']; 
$map = $_POST['map']; 
$img = "../rent_images/$names"; 

if(isset($_FILES['product_image'])){ 
    foreach($_FILES['product_image']['tmp_name'] as $key => $tmp_name){ 
     $file_name = $key.$_FILES['product_image']['name'][$key]; 
     $file_size =$_FILES['product_image']['size'][$key]; 
     $file_tmp =$_FILES['product_image']['tmp_name'][$key]; 
     $file_type=$_FILES['product_image']['type'][$key]; 
     if($file_size > 2097152){ 
      $error_msg ='File size must be less than 2 MB'; 
     }  
     $desired_dir=$img; 
     if(empty($error_msg)==true){ 
      if(is_dir($desired_dir)==false){ 
       mkdir("$desired_dir", 0755);  // Create directory if it does not exist 
      } 
       if(is_dir("$desired_dir/".$file_name)==false){ 
       move_uploaded_file($file_tmp,"$desired_dir/".$file_name); 
       } 
       else{         // rename the file if another one exist 
       $new_dir="$desired_dir/".$file_name.time(); 
       rename($file_tmp,$new_dir) ;    
       } 
     } 
    } 
    $sql_addProduct = mysqli_query($connection, "INSERT INTO rents(id,title,name,description,price,category,location,map,date_added) VALUES('','$title','$names','$description','$price','$category','$location','$map',now())"); 
    if(!$sql_addProduct){ 
     $error_msg = '<div class="atention">Couldn\'t upload the images or property details, please try again</div>'; 
    }else{ 
     header("location: property_list.php"); 
     exit(); 
    } 
} 
} 
?> 

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8" /> 
<title>Admin Panel</title> 
<link rel="stylesheet" type="text/css" href="style/bootstrap.css"> 
<link rel="stylesheet" href="style/style.css" type="text/css" media="screen"/> 

<script type="text/javascript" src="js/jquery-1.11.3.js"></script> 
<script type="text/javascript" src="js/bootstrap.min.js"></script> 
<script type="text/javascript"> 
    $(function(){ 
     var pull = $('#pull'); 
     menu = $('nav ul'); 
     menuHeight = menu.height(); 

     $(pull).on('click', function(e){ 
      e.preventDefault(); 
      menu.slideToggle(); 
     }); 
    }); 
</script> 
<script type="text/javascript"> 
    $(window).resize(function(){ 
     var w = $(window).width(); 
     if(w > 320 && menu.is(':hidden')){ 
      menu.removeAttr('style'); 
     } 
    }); 
</script> 
</head> 

<body> 
<div class="container"> 
<div> 
    <?php include_once("template/header.php"); ?> 
</div> 
<div class="row"> 
    <p><a href="property_list.php"> Click Here Update Property</a></p> 
    <table width="100%" cellpadding="0" cellspacing="0" border="0"> 
      <tr> 
       <td valign="top" width="100%"> 
        <section id="main_content"> 
         <h1>Add Product</h1> 
         <?php echo $error_msg; ?> 
         <form action="" method="post" enctype="multipart/form-data"> 
          <input type="text" class="input-login" name="title" placeholder="Title" maxlength="100"><br><br> 
          <input type="text" class="input-login" name="name" placeholder="Name" maxlength="100"><br><br> 
          <textarea cols="50" rows="10" name="description" placeholder="Detailed description"></textarea><br><br> 
          <input type="text" class="input-login" name="price" placeholder="Price" maxlength="15"><br><br> 
          <input name="category" class="input-login" placeholder="Category" maxlength="50"><br><br> 
          <input name="location" class="input-login" placeholder="location" maxlength="50"><br><br> 
          <textarea cols="50" rows="10" name="map" class="input-login" placeholder="Insert Google map address"></textarea><br><br> 
          <input type="file" name="product_image[]" multiple title="Select property images"><br> 
          <br/> 
          <button id="submitBTN">Add Product</button> 
         </form> 
        </section> 
       </td> 
      </tr> 
     </table> 
</div> 
<div> 
    <?php include_once("../template/footer.php"); ?> 
</div> 
</div> 
</body> 
</html> 
+0

你可能有間接的目錄名的問題。 Apache可能正在執行它在不同的目錄 – Forbs

+0

親切膨脹更多請。 – kaybee

回答

0

看起來像你的一個包括數據庫連接或admin_session是錯誤的。假設你將它們放置在同一個文件夾中。

+0

數據庫連接適用於項目中的所有腳本,這就是爲什麼它放在主文件夾中,而管理會話僅適用於後端。那對代碼先生的執行有影響嗎? – kaybee

0

打開數據庫配置文件,並改變你的用戶,主機和密碼

../php/db_connection.php

+0

你的意思是把它改成我在服務器上創建的那個?如果那是你的意思,我已經這樣做了,除非你的意思是我應該改變它。本地系統上的用戶,主機和密碼與服務器的不同。 – kaybee

+0

你可以顯示你的** ../php/db_connection.php **文件嗎?不是密碼和這樣的事情,請張貼另一個密碼不是真正的,我只想看到** sintax **,你的文件 –

+0

好吧,連接顯示在下面bcos我已經更新它,但仍然geting相同錯誤在服務器端:<?php $ connection = new mysqli(「localhost」,「root」,「password」,「tim」); if($ connection - > connect_error){ \t echo'Connection not ok'; \t exit(); } ?> – kaybee

相關問題