So I encountered a weird problem with my form. When I click the oplsaan button it does not run through the code in if(isset($_POST['opslaan'])). The thing is that PHP doesn't save the form data to the $_POST array. For example, when I click opslaan in the following form:
if(isset($_POST['wijzigen']))
{
$query_selecteren = 'SELECT *
FROM contacten';
$result = mysqli_query($link, $query_selecteren);
echo '<form id="wijzigingscherm" method="post" action="' . $_SERVER['PHP_SELF'] . '">';
echo '<table>
<tr>
<th>Keuze</th>
<th>Afbeelding</th>
<th>Voornaam</th>
<th>Achternaam</th>
<th>Woonplaats</th>
<th>Telefoonnummer</th>
<th>Adres</th>
<th>Postcode</th>
<th>Opmerking</th>
</tr>';
foreach ($result as $rij) {
echo '<tr>';
$rijnr%2==0 ? $rijkleur='#6B9ED1' : $rijkleur='#99B3CC';
echo '<td style="background-color' . $rijkleur .'"> <input type="checkbox" name="checkedUser" value="' . $rij['contact_id'] . '"/>';
echo '<td style="background-color'.$rijkleur.'"> <img src="ImgPersonen/profiel.jpg"/>';
echo '<td style="background-color:' . $rijkleur .'"> <input size="7" type="text" name="voornaam" placeholder="' . $rij['vnaam'] .'"/></td>';
echo '<td style="background-color:' . $rijkleur .'"> <input size="7" type="text" name="achternaam" placeholder="' . $rij['anaam'] . '"</td>';
echo '<td style="background-color:' . $rijkleur .'"> <input size="7" type="text" name="woonplaats" placeholder="' . $rij['wplaats'] . '"/></td>';
echo '<td style="background-color:' . $rijkleur .'"> <input size="7" type="text" name="telefoonnummer" placeholder="' . $rij['tnummer'] . '"/></td>';
echo '<td style="background-color:' . $rijkleur .'"> <input size="7" type="text" name="adres" placeholder="' . $rij['adres'] . '"/></td>';
echo '<td style="background-color:' . $rijkleur . '"> <input size="7" type="text" name="postcode" placeholder="' . $rij['postcode'] . '"/></td>';
echo '<td style="background-color:' . $rijkleur . '"> <input size="7" type="text" name="opmerking" placeholder="' . $rij['opmerking'] . '"/></td>';
$rijnr++;
echo '</tr>';
}
echo '</table>
<input type="submit" name="opslaan" style="width:15%;" value="Opslaan" />
<input type="submit" name="annuleren" style="width:15%;" value="Annuleren" />
</form>';
}
It should run this code which I placed under session_start
if(isset($_POST['opslaan']))
{
$query_opslaan = 'a query using the post data';
mysqli_query($link, $query_opslaan) or die(mysqli_error($query_opslaan));
header('location:'.$_SERVER['PHP_SELF']);
}
but the weird thing is that the if(isset($_POST['osplaan'])) doesn't work for some reason and I really don't know what I'm doing wrong here! Can someone please tell me what I'm doing wrong here?
print_r($_POST)