Heello, I was having problems with this php script. I am trying to echo a statement on a contact form depending on the data entered, but when I hit submit, I get a blank page. I belive the error is something small, but I can;t put my finger on it.
Could someone give me some guidence?
Thanks
Much appreciated!

<form action="ContactUs.php" method="POST">
<?php
$_POST $firstname=['fname'];
$_POST $products=['products'];
$_POST $email=['email'];

if
        (isset($_POST['fname']) ||;
        (isset($_POST['email']) ||;
        (isset($_POST['products']) ||;
         {
        ( echo "Thank you visitor for intrest in our products. We will contact you at a later date.");      
    }
} else  (echo "Thank you $fname for intrest in $products. We will contact you soon.");
}
?>`
Member Avatar for diafol

You're sending to ContactUs.php - I'm assuming this form is on the same page?

You start off with:

$_POST $firstname=['fname'];

This is incorrect - there is no such variable. Possibly:

$firstname = $_POST['fname'];

However, you need to check that the $_POST variables exist before assigning a variable to them, otherwise you'll get an error on first page load. You can do this:

if(isset($_POST['submit'])){  //assuming your submit button has a 'name' attribute set to 'submit'
    $firstname = $_POST['fname'];
    //etc for your other fields
    //they should all be set is you receive an ok (isset) from the submit button
    //whether they contain any info is a different matter - here you'll need validation
    //e.g. test email field contains a valid emal address etc.
}

Further to diafol's advice, in your current code, you have a lot wrong. This is what is should be (based on what you have already) - please compare this code to what you have to see your mistakes:

<!-- <form action="ContactUs.php" method="POST"> this shouldn't be here -->
<?php
if (isset($_POST)) {
    $firstname = $_POST['fname'];
    $products = $_POST['products'];
    $email = $_POST['email'];
    if (isset($firstname) && isset($email) && isset($products)) {
        echo "Thank you ".$firstname." for interest in ".$products.". We will contact you soon.";      
    } else {
        echo "Please complete the form correctly";
    }
}
?>

This is a vary basic example for you using your existing code, please combine with diafol's advice above.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.