$_POST Probleem
<html><body background="img/rj45.jpg" vlink="#FFFFFF" alink="#FFFFFF">
<div align="center">
<table border="0" cellpadding="2" cellspacing="4" style="border-collapse: collapse" bordercolor="#111111" width="550" height="366">
<tr>
<td width="550" height="43" colspan="2">
<p align="center"><b><font size="4" face="Verdana" color="#FFFFFF">Klantendatabase</font></b></td>
</tr>
<tr>
<td width="150" height="20"><font face="Verdana" size="2" color="#FFFFFF"><a href="inloggen.php" target="_self">inloggen</a></font></td>
<td width="380" height="319" rowspan="7">
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?
require "connect.php";
$datumin = date("d.m.Y");
$datumuit = date("d.m.Y");
if ($_POST["compid"]&& $_POST["merk"]&& $_POST["type"] && $_POST["oms"]&& $_POST["sn"]&& $_POST["datumin"]&& $_POST["datumuit"] && $_POST["hsid"])
{
$sql = "INSERT INTO kcomponent (compid, merk, type, oms, sn, dat_in, dat_uit, hsid,) VALUES ('$compid', '$merk', '$type', '$oms', '$sn', '$datumin', '$datumuit', '$hsid')";
$res = mysql_query($sql)or die (mysql_error());
if ($res)
{
echo "gegevens zijn verwerkt<p>";
echo "Ga naar <a href=\"overzichtonderdelen.php\">volgende</a>.";
}
else
{
echo "Sorry niet aangemeld. Er is iets misgegaan met het invoeren in de database.";
echo "<a href=\"inhoud.php\">Probeer het nog eens</a>";
}
}
else
{
if ($_POST["submit"])
echo "Enkele velden vergeten!";
echo "<div align='center'>";
echo "<center>";
echo "<table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='380' height='169'>";
echo "<tr><td width='380' height='117' align='center' colspan='2'><font color='#FFFFFF' size='4'face='verdana'>Nieuwe hardwarecomponent<br>toevoegen</font></td></tr>";
echo "<tr><td>";
echo "<form method='POST' action='$php_self'><select size='1' name='onderdelen'";
$sql = "SELECT * FROM comp_oms_id";
$res = mysql_query($sql)or die(mysql_error());
if (mysql_num_rows($res) >= 1 )
{
while
($row = mysql_fetch_row($res))
{
echo "<option value='$_POST[compid]'>$row[0]</option>";
}
}
echo "</select>";
//echo "</form>";
//echo "<form method='POST' action='$php_self'>";
echo "$hsid</td></tr>";
echo "<tr><td width='190' height='25'align='right'><font face='Verdana' color='#FFFFFF'>Merk:</font></td>";
echo "<td width='190' height='15'><input type='text' style='border-style: dashed; border-width: 0' maxlength='20' size='20' name='voornaam' value='$_POST[merk]'></td></tr>";
echo "<tr><td width='190' height='15' align='right'><font face='Verdana' color='#FFFFFF'>Type:</font></td>";
echo "<td width='190' height='15'><input type='text' style='border-style: dashed; border-width: 0' maxlength='20' size='20'name='achternaambedrijf' value='$_POST[type]'></td></tr>";
echo "<tr><td width='190' height='15' align='right'><font face='Verdana' color='#FFFFFF'>Omschrijving:</font></td>";
echo "<td width='190' height='15'><input type='text' style='border-style: dashed; border-width: 0' maxlength='20' size='20'name='straat' value='$_POST[oms]'></td></tr>";
echo "<tr><td width='190' height='15' align='right'><font face='Verdana' color='#FFFFFF'>Serial nummer:</font></td>";
echo "<td width='190' height='15'><input type='text' style='border-style: dashed; border-width: 0' maxlength='7' size='7' name='postcode' value='$_POST[sn]'></td></tr>";
echo "<tr><td width='380' height='15' colspan='2'>";
echo "<input type='submit' value='Verzenden' name='submit'></td></tr>";
echo "</form></table>";
echo "</center>";
echo "</div>";
}
?>
require "connect.php";
$datumin = date("d.m.Y");
$datumuit = date("d.m.Y");
if ($_POST["compid"]&& $_POST["merk"]&& $_POST["type"] && $_POST["oms"]&& $_POST["sn"]&& $_POST["datumin"]&& $_POST["datumuit"] && $_POST["hsid"])
{
$sql = "INSERT INTO kcomponent (compid, merk, type, oms, sn, dat_in, dat_uit, hsid,) VALUES ('$compid', '$merk', '$type', '$oms', '$sn', '$datumin', '$datumuit', '$hsid')";
$res = mysql_query($sql)or die (mysql_error());
if ($res)
{
echo "gegevens zijn verwerkt<p>";
echo "Ga naar <a href=\"overzichtonderdelen.php\">volgende</a>.";
}
else
{
echo "Sorry niet aangemeld. Er is iets misgegaan met het invoeren in de database.";
echo "<a href=\"inhoud.php\">Probeer het nog eens</a>";
}
}
else
{
if ($_POST["submit"])
echo "Enkele velden vergeten!";
echo "<div align='center'>";
echo "<center>";
echo "<table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='380' height='169'>";
echo "<tr><td width='380' height='117' align='center' colspan='2'><font color='#FFFFFF' size='4'face='verdana'>Nieuwe hardwarecomponent<br>toevoegen</font></td></tr>";
echo "<tr><td>";
echo "<form method='POST' action='$php_self'><select size='1' name='onderdelen'";
$sql = "SELECT * FROM comp_oms_id";
$res = mysql_query($sql)or die(mysql_error());
if (mysql_num_rows($res) >= 1 )
{
while
($row = mysql_fetch_row($res))
{
echo "<option value='$_POST[compid]'>$row[0]</option>";
}
}
echo "</select>";
//echo "</form>";
//echo "<form method='POST' action='$php_self'>";
echo "$hsid</td></tr>";
echo "<tr><td width='190' height='25'align='right'><font face='Verdana' color='#FFFFFF'>Merk:</font></td>";
echo "<td width='190' height='15'><input type='text' style='border-style: dashed; border-width: 0' maxlength='20' size='20' name='voornaam' value='$_POST[merk]'></td></tr>";
echo "<tr><td width='190' height='15' align='right'><font face='Verdana' color='#FFFFFF'>Type:</font></td>";
echo "<td width='190' height='15'><input type='text' style='border-style: dashed; border-width: 0' maxlength='20' size='20'name='achternaambedrijf' value='$_POST[type]'></td></tr>";
echo "<tr><td width='190' height='15' align='right'><font face='Verdana' color='#FFFFFF'>Omschrijving:</font></td>";
echo "<td width='190' height='15'><input type='text' style='border-style: dashed; border-width: 0' maxlength='20' size='20'name='straat' value='$_POST[oms]'></td></tr>";
echo "<tr><td width='190' height='15' align='right'><font face='Verdana' color='#FFFFFF'>Serial nummer:</font></td>";
echo "<td width='190' height='15'><input type='text' style='border-style: dashed; border-width: 0' maxlength='7' size='7' name='postcode' value='$_POST[sn]'></td></tr>";
echo "<tr><td width='380' height='15' colspan='2'>";
echo "<input type='submit' value='Verzenden' name='submit'></td></tr>";
echo "</form></table>";
echo "</center>";
echo "</div>";
}
?>
</td>
</tr>
<tr>
<td width="150" height="20"><font face="Verdana" size="2"><a style='color: #FFFFFF' href="overzichtklanten.php" target="_self">klanten
overzicht</a></font></td>
</tr>
<tr>
<td width="150" height="20"><font face="Verdana" size="2">zoek</font></td>
</tr>
<tr>
<td width="150" height="20"><font face="Verdana" size="2">etc</font></td>
</tr>
<tr>
<td width="150" height="20"><font face="Verdana" size="2"><a style='color: #FFFFFF' href="invulklanten.php" target="_self">nieuwe<br>klanten<br>invoer.</a></font></td>
</tr>
<tr>
<td width="150" height="20"><font face="Verdana" size="2"><a style='color: #FFFFFF' href="index.php" target="_self">home</a></font></td>
</tr>
<tr>
<td width="150" height="190"> <td>
</tr>
</table>
</div></body></html>
Tevens is submit meestal geen goede manier van het controleren want als je in een input veld op enter druk wordt het formulier gesubmit zonder de waarde van de knop door te sturen.
als je in een <input> name=test hebt staan moet je bij if($_POST['test']) natuurlijk wel diezelfde naam gebruiken.. hier gebruik je in de je form hele andere namen dan in je verwerking
dus bv:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
if($_POST['naam'] && $_POST['plaats']){
//verwerk het zelf maar
}
<form method='post'>
<input type='text' name='naam'>
<input type='text' name='plaats'>
<input type='submit' name='submit'>
</form>
php?>
if($_POST['naam'] && $_POST['plaats']){
//verwerk het zelf maar
}
<form method='post'>
<input type='text' name='naam'>
<input type='text' name='plaats'>
<input type='submit' name='submit'>
</form>
php?>