-1

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

?>
Vipul Behl
  • 644
  • 1
  • 7
  • 20
  • Please check apache/php error logs and advise – zanderwar Nov 29 '14 at 13:56
  • 2
    A 500 error in PHP always means you need to look in your web server's error log for more details, where the error will be more fully reported. Always when developing and testing code, enable PHP's error display so the fatal error is shown on screen in detail. At the top of your script `error_reporting(E_ALL); ini_set('display_errors', 1);` and remove that when your code goes into production. – Michael Berkowski Nov 29 '14 at 13:56
  • 1
    If this is truly your exact code, including the comment in `` at the top of the PHP script and newlines before the opening ` – Michael Berkowski Nov 29 '14 at 13:57
  • Use mysqli or PDO because mysql_* functions are going to be deprecated in >= 5.5.0 versions – webblover Nov 29 '14 at 14:06
  • Hi Michael i don't have those comments in my code, I wrote the comments so that others can understand what i am trying to say. – Vipul Behl Nov 29 '14 at 16:47

1 Answers1

0

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

  • i have already created the upload folder and the connection parameters are right. How to check if i have write permissions for a folder or not? – Vipul Behl Nov 29 '14 at 16:45