I developped a PHP website on an Apashe Server who worked just fine. When moved to my client's IIS Server we have a lot of errors like this one :
[18-May-2017 16:35:15 Asia/Kuwait] PHP Notice: Undefined index: coupon in C:\inetpub\wwwroot\tourdesoceans\ville.php on line 61
I understand the error and checked the variables using isset(), !empty(), var_dump() and using $_GET instead of $_POST and they all seem to return expected results.
Here's a part of the form I'm using (I shortened it for this post) :
<form class="inscription" method="post">
<a href="/">Choisissez une autre ville</a>
<h1>ÉVÈNEMENT <?php echo $data['ville']; ?></h1>
<p><strong>RÉSERVÉ AUX PROFESSIONNELS</strong></p>
<p class="vip"><strong>Vous disposez d'une invitation VIP ?</strong><br />
Merci de renseigner le code présent sur votre coupon :<br />
<input type="text" name="coupon" value="<?php echo $_POST['coupon']; ?>" />
<?php echo $erreur; ?></p>
<label>Agence de voyage* :</label>
<input type="text" name="agence" value="<?php echo $_POST['agence']; ?>" required />
<label>Nom* :</label>
<input type="text" name="nom" value="<?php echo $_POST['nom']; ?>" required />
<label>Prénom* :</label>
<input type="text" name="prenom" value="<?php echo $_POST['prenom']; ?>" required />
<label>Email* :</label>
<input type="email" name="email" value="<?php echo $_POST['email']; ?>" required />
<label>Téléphone* :</label>
<input type="tel" name="telephone" pattern="^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$" value="<?php echo $_POST['telephone']; ?>" required />
<label>Adresse professionnelle* :</label>
<textarea name="adresse" required><?php echo $_POST['adresse']; ?></textarea>
<label>Code postal* :</label>
<input type="text" name="cpostal" value="<?php echo $_POST['cpostal']; ?>" required />
<label>Ville* :</label>
<input type="text" name="ville" value="<?php echo $_POST['ville']; ?>" required />
<input type="hidden" name="lieu" value="<?php echo strtolower($_POST['id']);?>" required />
<input type="submit" value="Valider ma demande d’inscription" />
<p>Si vous ne disposez pas d'une invitation VIP, <strong>rendez-vous le 1er juin 2017 pour vous inscrire !</strong></p>
<p class="mention">*Champs obligatoires</p>
</form>
Here's how I get the variables and send them to the database :
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
////////// PROTECTION DES DONNEES ENVOYEES //////////
$coupon = htmlspecialchars(addslashes($_POST['coupon']));
$agence = htmlspecialchars(addslashes($_POST['agence']));
$nom = htmlspecialchars(addslashes($_POST['nom']));
$prenom = htmlspecialchars(addslashes($_POST['prenom']));
$email = htmlspecialchars(addslashes($_POST['email']));
$telephone = htmlspecialchars(addslashes($_POST['telephone']));
$adresse = htmlspecialchars(addslashes($_POST['adresse']));
$cpostal = htmlspecialchars(addslashes($_POST['cpostal']));
$ville = htmlspecialchars(addslashes($_POST['ville']));
$lieu = htmlspecialchars(addslashes($_POST['lieu']));
die(var_dump($_POST));
// ENVOI A LA BDD
$sql = "INSERT INTO tui_inscription (id, coupon, agence, nom, prenom, email, telephone, adresse, cpostal, ville, lieu) ";
$sql .= "VALUES('', '".$coupon."', '".$agence."', '".$nom."', '".$prenom."', '".$email."', '".$telephone."', '".$adresse."', '".$cpostal."', '".$ville."', '".$lieu."')";
$sql_add = mysqli_query($connexion, $sql)
or die ("Impossible de finaliser l'inscription");
}
Here's a var_dump($_POST) after sending the form :
array(10) { ["coupon"]=> string(8) "VIPTDO17" ["agence"]=> string(4) "Lyon" ["nom"]=> string(6) "MYNAME" ["prenom"]=> string(9) "MYSURNAME" ["email"]=> string(15) "email@gmail.com" ["telephone"]=> string(10) "0123456789" ["adresse"]=> string(10) "MY ADDRESS" ["cpostal"]=> string(5) "69007" ["ville"]=> string(4) "TOWN" ["lieu"]=> string(0) "" }
They all marked as Undefined Index error in the logs !
Please let me know what further information you need to help me.