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 ;)

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

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能