簡體   English   中英

php腳本在系統上本地工作,但不在服務器上工作

[英]php script working on locally on the system but not on the server

請幫助我瀏覽下面的代碼,看看哪里有錯誤,因為這些代碼在我的系統上本地運行,但在服務器上運行不正常。 它可以將圖像移動到文件夾,但是數據不會移動到數據庫。 我已經檢查了一下,但不能真正將手放在錯誤上,很快我將非常感謝您的幫助。 謝謝。

<?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>

看起來您的數據庫連接包含項之一或admin_session錯誤。 假設您將它們放置在同一文件夾中。

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

../php/db_connection.php

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM