'Problem with using if(isset($_POST["submit"])){ with php post form submittal

I have read several of the posts here however I still do not know what went wrong using if(isset($_POST["submit"]) for form submission. I made use of in htm file. Any ideas? I made use of a form submition button in html and tried to use the press of the submit button to send data from the form to the php page but I keep getting errors.

<!DOCTYPE html>
<html>
<body>
<?php
if(isset($_POST["submit"])){

    $product = $_POST['Product'];
    $description = $_POST['Description'];
    $price = $_POST['Price'];
    $paypal = $_POST['paypal'];
    $shipping = $_POST['shiprice'];
    $photoss = $_POST['image_uploads'];
}
if(empty($product)) {
    $errorMessage .= "<li>You forgot to enter a product</li>";
}
if(empty($description)) {
    $errorMessage .= "<li>You forgot to enter a description!</li>";
}
if(empty($price)) {
    $errorMessage .= "<li>You forgot to enter a price!</li>";
}
if(empty($paypal)) {
    $errorMessage .= "<li>You forgot to enter your paypal!</li>";
}
if(empty($shipping)) {
    $errorMessage .= "<li>You forgot to enter a shipping price</li>";
}

echo 'Buy a '.$product.'!';
echo "<br>";
echo 'Description: '.$description.'!';
echo "<br>";
echo 'Price '.$price.'!';
echo "<br>";
echo 'Cost of shipping'.$shipping.'!';
echo "<br>";
echo 'pay to'.$paypal.'!';
?>
</body>
</html>
<link rel="stylesheet" type="text/css" href="syling.css"/>

<div id = "uploadpage">

<h3>
Please Upload your item that you want to sell here 
</h3>

<div id="navigate">
<h2> Navigation </h2>
<ul>

<li> <a class = "selected" href = "website.htm" >Home </a> </li>
<li>  <a href = "aboutpage.htm" >about </a>  </li>
<li> <a href = "accountpage.htm" >account </a>  </li>
</ul>
</div>

<form action = "formhandling.php" method = "post"  autocomplete = "off" >

<h2>
Item: <input type = "text" name = "Product" value = "" size = "45" maxlength = "70"
</h2>


<h2>
Description: <input type = "text" name = "Description" value = "" size = "45" maxlength = "700"
</h2>

<h2>
Price: <input type = "text" name = "Price" value = "" size = "25" maxlength = "70"
</h2>

<h2>
Paypal Email to get paid: <input type = "text" name = "paypal" value = "" size = "25" maxlength = "200"
</h2>

<h2>
Price to ship: <input type = "text" name = "shiprice" value = "" size = "25" maxlength = "70"
</h2>

<h2>
 <div>
    <label for="image_uploads">Choose images to upload (PNG, JPG)</label>
    <input type="file" id="image_uploads" name="image_uploads" accept=".jpg, .jpeg, .png" multiple>
  </div>
  <div class="preview">
    <p>No files currently selected for upload</p>
  </div>
<input type="submit" value="submit" name="submit" >
</form>
</h2>


Solution 1:[1]

All the code that uses the form submission parameters needs to be inside that if statement.

And if any of the inputs are invalid, you should display $errorMessage instead of the normal output.

<?php
if(isset($_POST["submit"])){
    $product = $_POST['Product'];
    $description = $_POST['Description'];
    $price = $_POST['Price'];
    $paypal = $_POST['paypal'];
    $shipping = $_POST['shiprice'];
    $photoss = $_POST['image_uploads'];
    if(empty($product)) {
        $errorMessage .= "<li>You forgot to enter a product</li>";
    }
    if(empty($description)) {
        $errorMessage .= "<li>You forgot to enter a description!</li>";
    }
    if(empty($price)) {
        $errorMessage .= "<li>You forgot to enter a price!</li>";
    }
    if(empty($paypal)) {
        $errorMessage .= "<li>You forgot to enter your paypal!</li>";
    }
    if(empty($shipping)) {
        $errorMessage .= "<li>You forgot to enter a shipping price</li>";
    }

    if (empty($errorMessage)) {
        echo 'Buy a '.$product.'!';
        echo "<br>";
        echo 'Description: '.$description.'!';
        echo "<br>";
        echo 'Price '.$price.'!';
        echo "<br>";
        echo 'Cost of shipping'.$shipping.'!';
        echo "<br>";
        echo 'pay to'.$paypal.'!';
    } else {
        echo "<ul>$errorMessage</ul>";
    }
}
?>

Solution 2:[2]

I found out that since wamp was running in internet explore that the code was not running properly. Hmmmmmmm

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Barmar
Solution 2 Simon