PHP代码提供500内部服务器错误

时间:2014-11-29 13:49:02

标签: php html

我正在制作一个交易网站,并试图让用户上传广告。我写的代码运行正常,当我在localhost上运行时没有错误。但是,当我托管该网站,然后尝试上传广告时,我得到了" 500内部服务器错误"。我没有对代码进行任何更改。

提交文件

<html>
<head>
<title>Submit Ad</title>
<link rel="stylesheet" type="text/css" href="css/signup.css"/>
</head>

<?php
require('heading.php');
?>

<form class="submit-ad" action="submitad_validation.php" method="POST" enctype="multipart/form-data">
    <h1 class="sign-up-title">Submit Ad</h1>
    <input type="text" name="title" class="sign-up-input" placeholder="Title" required  autofocus>
    <input type="text" name="description" class="sign-up-input" placeholder="Description" required>
    <input type="text" name="contact" class="sign-up-input" placeholder="Email ID" required>
    <input type="text" name="price" class="sign-up-input" placeholder="Expected Price" required>

    <select class="sign-up-input" name="categories" required>
      <option value="mobile">Mobiles and Accessories</option>
      <option value="laptop">Laptops and Accessories</option>
      <option value="cars">Cars</option>
      <option value="bikes">Bikes</option>
      <option value="appliances">Home Appliances</option>
      <option value="books">Books</option>
      <option value="jewelery">Jewelery</option>
      <option value="music">Musical Instruments</option>
      <option value="pets">Pets</option>
    </select> 

    <!-- Code to upload the image of the item -->
    <input type="file" name="imageUpload" id="imageUpload"> 
    <input type="submit" value="Submit Ad" name="submit" class="sign-up-button">

</form>  
</html>

submitadvalidation文件

<!--This page is used to get the ad data from the user and then store it in the database-->

<?php
require('connection.php');
session_start();
$title=$_POST['title'];
$description=$_POST['description'];
$value=$_POST['categories'];
$price=$_POST['price'];
$contact=$_POST['contact'];
$id=$_SESSION['user_id'];

if(isset($_POST['submit']))
{

    //Process the image that is uploaded by the user

    $target_dir = "uploads/";
    $target_file = $target_dir . basename($_FILES["imageUpload"]["name"]);
    $uploadOk = 1;
    $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

        if (move_uploaded_file($_FILES["imageUpload"]["tmp_name"], $target_file)) {
            echo "The file ". basename( $_FILES["imageUpload"]["name"]). " has been uploaded.";
        } else {
            echo "Sorry, there was an error uploading your file.";}

    $image=basename( $_FILES["imageUpload"]["name"],".jpg"); // used to store the filename in a variable

    //storing the data in your database
    $query= "INSERT INTO items VALUES ('$id','$title','$description','$price','$value','$contact','$image')";
    mysql_query($query);

    require('heading.php');
    echo "Your add has been submited, you will be redirected to your account page in 3 seconds....";
    //redirecting the user back to the account page after successful uploading of the ad
    header( "Refresh:3; url=account.php", true, 303);
}

?>

1 个答案:

答案 0 :(得分:0)

可能您还没有创建uploads文件夹,或者您没有上传文件夹的写入权限,或者没有错误的数据库连接参数。

检查这些事情

P.S。如果您可以启用错误消息,则可以立即找到问题;)