2017-04-12 125 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