douzhi6160 2014-11-29 13:49
浏览 84
已采纳

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

I am making a trading website and am trying to make users to upload ads. The code that i have written is running fine with no errors when i run it on localhost. But when i hosted the site and then tried to upload the ad i got "500 internal server error". I have made no changes to the code.

submitad file

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

<!--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条回答 默认 最新

  • dousongxuan7507 2014-11-29 13:57
    关注

    Probably you haven't create the uploads folder, or you haven't the write permission for the uploads folder, or again wrong connection parameter to database.

    Check these things

    P.S. If you can enable the error messages you find the problem immediately ;)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 定制ai直播实时换脸软件
  • ¥100 栈回溯相关,模块加载后KiExceptionDispatch无法正常回溯了
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding
  • ¥15 Marscode IDE 如何预览新建的 HTML 文件
  • ¥15 K8S部署二进制集群过程中calico一直报错
  • ¥15 java python或者任何一种编程语言复刻一个网页
  • ¥20 如何通过代码传输视频到亚马逊平台
  • ¥15 php查询mysql数据库并显示至下拉列表中