2014-11-29 13:49


  • php
  • html

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

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


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

    <!-- 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">


submitadvalidation file

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



    //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')";

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

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享