Updaten met checkbox werkt niet
Voorbeeld op http://www.kwarto.be/bestel.php
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
$host="localhost"; // Host name
$username="*****"; // Mysql username
$password="*****"; // Mysql password
$db_name="*****"; // Database name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT supplies.*, jss_products.name as name, inkoop.* FROM inkoop inner join supplies on inkoop.oemcode = supplies.oemcode inner join jss_products on supplies.oemcode = jss_products.suppliercode where besteld = '0'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
<!--
body,td,th {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
-->
</style><table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="14" bgcolor="#FFFFFF"><strong>Bestellingen </strong></td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF"><input type="checkbox" onClick="Checkall(this.form);" /><strong>Alles</strong><br /></td>
<td align="center" bgcolor="#FFFFFF"><strong>Datum</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Aantal</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Oemcode</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Omschrijving</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Klant</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Filiaal</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Verkoper</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="item" type="checkbox" id="item" value="<? echo $rows['ID']; ?>"></td>
<td bgcolor="#FFFFFF"><? echo $rows['datum'];?></td>
<td bgcolor="#FFFFFF"><? echo $rows['aantal']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['oemcode']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['name']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['klant']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['filiaal']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['verkoper']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="14" align="center" bgcolor="#FFFFFF"><INPUT TYPE="button" VALUE="Bestelling printen" onClick="printPage()"></td>
</tr>
<tr>
<td colspan="14" align="center" bgcolor="#FFFFFF"><input name="update" type="submit" id="update" value="Bestelling verwerken"></td>
</tr>
<?
// Check if update button active, start this
if (isset($update)) {
$item = $_POST['item'];
for($i=0;$i<$count;$i++){
$del_id = $item[$i];
$sql = "UPDATE supplies set besteld='1' WHERE ID='$del_id'";
$result = mysql_query($sql);
}
// if successful redirect to bestel.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=bestel.php\">";
}
}
mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>
$host="localhost"; // Host name
$username="*****"; // Mysql username
$password="*****"; // Mysql password
$db_name="*****"; // Database name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT supplies.*, jss_products.name as name, inkoop.* FROM inkoop inner join supplies on inkoop.oemcode = supplies.oemcode inner join jss_products on supplies.oemcode = jss_products.suppliercode where besteld = '0'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
<!--
body,td,th {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
-->
</style><table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="14" bgcolor="#FFFFFF"><strong>Bestellingen </strong></td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF"><input type="checkbox" onClick="Checkall(this.form);" /><strong>Alles</strong><br /></td>
<td align="center" bgcolor="#FFFFFF"><strong>Datum</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Aantal</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Oemcode</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Omschrijving</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Klant</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Filiaal</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Verkoper</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="item" type="checkbox" id="item" value="<? echo $rows['ID']; ?>"></td>
<td bgcolor="#FFFFFF"><? echo $rows['datum'];?></td>
<td bgcolor="#FFFFFF"><? echo $rows['aantal']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['oemcode']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['name']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['klant']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['filiaal']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['verkoper']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="14" align="center" bgcolor="#FFFFFF"><INPUT TYPE="button" VALUE="Bestelling printen" onClick="printPage()"></td>
</tr>
<tr>
<td colspan="14" align="center" bgcolor="#FFFFFF"><input name="update" type="submit" id="update" value="Bestelling verwerken"></td>
</tr>
<?
// Check if update button active, start this
if (isset($update)) {
$item = $_POST['item'];
for($i=0;$i<$count;$i++){
$del_id = $item[$i];
$sql = "UPDATE supplies set besteld='1' WHERE ID='$del_id'";
$result = mysql_query($sql);
}
// if successful redirect to bestel.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=bestel.php\">";
}
}
mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>
Gewijzigd op 01/01/1970 01:00:00 door Robbie
Tip: Gooi alle opmaak uit de html-code en gebruik een css-stylesheet om de boel op te maken. Is een stuk eenvoudiger en veel beter te onderhouden.
Edit: En wanneer de query mislukt, doe je niets met de foutmelding. Zo heb je natuurlijk ook niets aan de foutafhandeling.
Gewijzigd op 01/01/1970 01:00:00 door Frank -
Gewijzigd op 01/01/1970 01:00:00 door Scrptr
Ik heb deze regel bijgevoegd
en zie dat er inderdaad niets is gewijzigd.
Wat kan er zijn misgelopen?
Alvast bedankt
Gewijzigd op 01/01/1970 01:00:00 door Robbie
Code (php)
1
2
3
4
2
3
4
<?
$sql = "UPDATE supplies set besteld='1' WHERE id='$del_id'" or trigger_error(mysql_error());;
?>
$sql = "UPDATE supplies set besteld='1' WHERE id='$del_id'" or trigger_error(mysql_error());;
?>
Code (php)
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
<?
$sql = "
UPDATE supplies SET besteld = 1
WHERE id= " . $del_id;
if (!$res = mysql_query ($sql)) {
trigger_error (mysql_error ());
}
?>
$sql = "
UPDATE supplies SET besteld = 1
WHERE id= " . $del_id;
if (!$res = mysql_query ($sql)) {
trigger_error (mysql_error ());
}
?>
Probleem opgelost! Yes!!
Ik had dezelfde ID naam in 2 tabellen waardoor hij de verkeerde aannam.