foreach bad argument probleem
Hiermee kan ik flyers toevoegen aan de agenda en uploaden.
Nu heb ik dit zelfde scriptje op een andere site draaien en krijg nu deze melding:
Warning: Invalid argument supplied for foreach() in /storage/mijndomein/users/046660/public/sites/www.drentsebuurt.nl/admin/agendaadmin.php on line 16
Dit is het script:
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<html>
<head>
<title>agenda</title>
<link rel="stylesheet" type="text/css"
href="../style.css" />
</head>
<body>
<?php
include '../config.php';
include '../opendb.php';
include '../timeFunctionsagenda.php';
include '../displayFunctionsagenda.php';
//picture upload var
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["pictures"]["tmp_name"][0];
zzz
$name = $_FILES["pictures"]["name"][0];
$name1 = $_FILES["pictures"]["name"][1];
move_uploaded_file($tmp_name, "../flyers/$name");
move_uploaded_file($tmp_name1, "../flyers/$name1");
chmod("../flyers/$name", 0777);
chmod("../flyers/$name1", 0777);
}
}
// get variables from form post for which record to change, and what to do with it
$action = $_GET['action'];
$id = $_GET['id'];
// THE DELETE OPTION
if($action == 'delete')
{
// set up delete query
$query = "DELETE FROM events WHERE id =" . $id;
// do the query
mysql_query($query) or die('Error, query failed');
echo "event deleted successfully!<br><br><a href='agenda.php'>add a new event</a>";
}
// THE ADD OR EDIT OPTION
elseif (isset($_POST['add']) || isset($_POST['edit']))
{
// get date from form post
$date = $_POST['year'] . '-' . $_POST['month'] . '-' . $_POST['day'];
// get time from form post
$rawTime = $_POST['time'];
// convert time to MySQL format
if($rawTime > 11 )
{
$rawTime = '0';
}
$time = ($rawTime + $_POST['ampm']) . ':' . $_POST['minute'] . ':00';
// get showTime
$showTime = $_POST['showTime'];
// showTime to 1 or 0
if ($showTime == "on")
{
$showTime = 1;
}
else
{
$showtime = 0;
}
// get venue
$venue = $_POST['venue'];
// get description
$description = $_POST['description'];
// get hoogte
$hoogte = $_POST['hoogte'];
// get breedte
$breedte = $_POST['breedte'];
// set up insert query
if (isset($_POST['add'])) {
$query = "INSERT INTO events (date, time, showTime, venue, description, flyerfront, flyerback, hoogte, breedte) VALUES ('$date', '$time', '$showTime', '$venue', '$description', '$name', '$name1', '$hoogte', '$breedte')";
}
// set up update query
elseif (isset($_POST['edit'])) {
$query = "UPDATE events SET date = '$date', time = '$time', showTime = '$showTime', hoogte = '$hoogte', breedte = '$breedte', venue = '$venue', description = '$description' WHERE id ='$id'";
}
// do the query
mysql_query($query) or die('Error, insert query failed');
echo "events list updated successfully!<br><br><a href='agenda.php'>add a new event</a>";
}
// ADD/EDIT FORM
else
{
// load stored values for editing event
if($action == 'edit')
{
$query = "SELECT * FROM events WHERE id='$id'";
$result = mysql_query($query);
$date = mysql_result($result,0,"date");
$time = mysql_result($result,0,"time");
$venue = mysql_result($result,0,"venue");
$description = mysql_result($result,0,"description");
$breedte = mysql_result($result,0,"breedte");
$hoogte = mysql_result($result,0,"hoogte");
$name = mysql_result($result,0,"flyerfront");
$name1 = mysql_result($result,0,"flyerback");
$month = substr($date, 5, 2);
$day = substr($date, 8, 2);
$year = substr($date, 0, 4);
$hour = realHour($time);
$minute = substr($time, 3, 2);
$ampm = realAMPM($time);
$showTime = mysql_result($result,0,"showTime");
}
?>
<form method="post" action="" enctype="multipart/form-data">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">Date</td>
<td>
<select name="month" id="month">
<option value="01" <?php if ($month == "01") {echo "selected";} ?>>Jan
<option value="02" <?php if ($month == "02") {echo "selected";} ?>>Feb
<option value="03" <?php if ($month == "03") {echo "selected";} ?>>Mar
<option value="04" <?php if ($month == "04") {echo "selected";} ?>>Apr
<option value="05" <?php if ($month == "05") {echo "selected";} ?>>May
<option value="06" <?php if ($month == "06") {echo "selected";} ?>>Jun
<option value="07" <?php if ($month == "07") {echo "selected";} ?>>Jul
<option value="08" <?php if ($month == "08") {echo "selected";} ?>>Aug
<option value="09" <?php if ($month == "09") {echo "selected";} ?>>Sep
<option value="10" <?php if ($month == "10") {echo "selected";} ?>>Oct
<option value="11" <?php if ($month == "11") {echo "selected";} ?>>Nov
<option value="12" <?php if ($month == "12") {echo "selected";} ?>>Dec
</select>
<select name="day" id="day">
<option value="01" <?php if ($day == "01") {echo "selected";} ?>>1
<option value="02" <?php if ($day == "02") {echo "selected";} ?>>2
<option value="03" <?php if ($day == "03") {echo "selected";} ?>>3
<option value="04" <?php if ($day == "04") {echo "selected";} ?>>4
<option value="05" <?php if ($day == "05") {echo "selected";} ?>>5
<option value="06" <?php if ($day == "06") {echo "selected";} ?>>6
<option value="07" <?php if ($day == "07") {echo "selected";} ?>>7
<option value="08" <?php if ($day == "08") {echo "selected";} ?>>8
<option value="09" <?php if ($day == "09") {echo "selected";} ?>>9
<option <?php if ($day == "10") {echo "selected";} ?>>10
<option <?php if ($day == "11") {echo "selected";} ?>>11
<option <?php if ($day == "12") {echo "selected";} ?>>12
<option <?php if ($day == "13") {echo "selected";} ?>>13
<option <?php if ($day == "14") {echo "selected";} ?>>14
<option <?php if ($day == "15") {echo "selected";} ?>>15
<option <?php if ($day == "16") {echo "selected";} ?>>16
<option <?php if ($day == "17") {echo "selected";} ?>>17
<option <?php if ($day == "18") {echo "selected";} ?>>18
<option <?php if ($day == "19") {echo "selected";} ?>>19
<option <?php if ($day == "20") {echo "selected";} ?>>20
<option <?php if ($day == "21") {echo "selected";} ?>>21
<option <?php if ($day == "22") {echo "selected";} ?>>22
<option <?php if ($day == "23") {echo "selected";} ?>>23
<option <?php if ($day == "24") {echo "selected";} ?>>24
<option <?php if ($day == "25") {echo "selected";} ?>>25
<option <?php if ($day == "26") {echo "selected";} ?>>26
<option <?php if ($day == "27") {echo "selected";} ?>>27
<option <?php if ($day == "28") {echo "selected";} ?>>28
<option <?php if ($day == "29") {echo "selected";} ?>>29
<option <?php if ($day == "30") {echo "selected";} ?>>30
<option <?php if ($day == "31") {echo "selected";} ?>>31
</select>
,
<select name="year" id="year">
<option <?php if ($year == (date('Y') - 3)) {echo "selected";} echo ">" . (date('Y') - 3); ?>
<option <?php if ($year == (date('Y') - 2)) {echo "selected";} echo ">" . (date('Y') - 2); ?>
<option <?php if ($year == (date('Y') - 1)) {echo "selected";} echo ">" . (date('Y') - 1); ?>
<option <?php if (($year == date('Y')) OR (!isset($year))) {echo "selected";} echo ">" . date('Y'); ?>
<option <?php if ($year == (date('Y') + 1)) {echo "selected";} echo ">" . (date('Y') + 1); ?>
<option <?php if ($year == (date('Y') + 2)) {echo "selected";} echo ">" . (date('Y') + 2); ?>
<option <?php if ($year == (date('Y') + 3)) {echo "selected";} echo ">" . (date('Y') + 3); ?>
<option <?php if ($year == (date('Y') + 4)) {echo "selected";} echo ">" . (date('Y') + 4); ?>
</select>
</td>
</tr>
<tr>
<td width="100">Venue</td>
<td>
<textarea name="venue" id="venue" rows="5" cols="80"><?php if (isset($venue)) {echo $venue;} ?></textarea>
</td>
</tr>
<tr>
<td width="100">Description</td>
<td>
<textarea name="description" id="description" rows="5" cols="80"><?php if (isset($description)) {echo $description;} ?></textarea>
</td>
</tr>
<tr>
<td width="100">Flyer Front </td>
<td><input type="file" name="pictures[0]" /><?php if (isset($name)) {echo $name;} ?></td>
</tr>
<tr>
<td>Flyer Back </td>
<td><input type="file" name="pictures[1]" /><?php if (isset($name1)) {echo $name1;} ?></td>
</tr>
<tr>
<td>Hoogte</td>
<td><input type="text" name="hoogte" id="hoogte" <?php if (isset($hoogte)) {echo "value=" . $hoogte;} ?>></td>
</tr>
<tr>
<td>Breedte</td>
<td><input type="text" name="breedte" id="breedte" <?php if (isset($breedte)) {echo "value=" . $breedte;} ?>></td>
</tr>
<tr>
<td> </td>
<td><?php
if ($action == 'edit')
{
echo "<input name='edit' type='submit' id='edit' value='update event'>";
}
else
{
echo "<input name='add' type='submit' id='add' value='add event'>";
}
?></td>
</tr>
</table>
</form>
<?php
}
?>
<table border="0" cellspacing="3">
<tr>
<td colspan="9" align="center" class="highlight">
UPCOMING EVENTS
</td>
</tr>
<?php
$query = "SELECT * FROM events ORDER BY date ASC";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
if ($row['date'] >= date('Y-m-d'))
{
displayEvents($row);
displayActions($row);
}
}
?>
</table>
<BR>
<BR>
<table border="0" cellspacing="3">
<tr>
<td colspan="9" align="center" class="highlight">
PAST EVENTS
</td>
</tr>
<?php
$query = "SELECT * FROM events ORDER BY date DESC";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
if ($row['date'] <= date('Y-m-d'))
{
displayEvents($row);
displayActions($row);
}
}
include '../closedb.php';
?>
</table>
</body>
</html>
<head>
<title>agenda</title>
<link rel="stylesheet" type="text/css"
href="../style.css" />
</head>
<body>
<?php
include '../config.php';
include '../opendb.php';
include '../timeFunctionsagenda.php';
include '../displayFunctionsagenda.php';
//picture upload var
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["pictures"]["tmp_name"][0];
zzz
$name = $_FILES["pictures"]["name"][0];
$name1 = $_FILES["pictures"]["name"][1];
move_uploaded_file($tmp_name, "../flyers/$name");
move_uploaded_file($tmp_name1, "../flyers/$name1");
chmod("../flyers/$name", 0777);
chmod("../flyers/$name1", 0777);
}
}
// get variables from form post for which record to change, and what to do with it
$action = $_GET['action'];
$id = $_GET['id'];
// THE DELETE OPTION
if($action == 'delete')
{
// set up delete query
$query = "DELETE FROM events WHERE id =" . $id;
// do the query
mysql_query($query) or die('Error, query failed');
echo "event deleted successfully!<br><br><a href='agenda.php'>add a new event</a>";
}
// THE ADD OR EDIT OPTION
elseif (isset($_POST['add']) || isset($_POST['edit']))
{
// get date from form post
$date = $_POST['year'] . '-' . $_POST['month'] . '-' . $_POST['day'];
// get time from form post
$rawTime = $_POST['time'];
// convert time to MySQL format
if($rawTime > 11 )
{
$rawTime = '0';
}
$time = ($rawTime + $_POST['ampm']) . ':' . $_POST['minute'] . ':00';
// get showTime
$showTime = $_POST['showTime'];
// showTime to 1 or 0
if ($showTime == "on")
{
$showTime = 1;
}
else
{
$showtime = 0;
}
// get venue
$venue = $_POST['venue'];
// get description
$description = $_POST['description'];
// get hoogte
$hoogte = $_POST['hoogte'];
// get breedte
$breedte = $_POST['breedte'];
// set up insert query
if (isset($_POST['add'])) {
$query = "INSERT INTO events (date, time, showTime, venue, description, flyerfront, flyerback, hoogte, breedte) VALUES ('$date', '$time', '$showTime', '$venue', '$description', '$name', '$name1', '$hoogte', '$breedte')";
}
// set up update query
elseif (isset($_POST['edit'])) {
$query = "UPDATE events SET date = '$date', time = '$time', showTime = '$showTime', hoogte = '$hoogte', breedte = '$breedte', venue = '$venue', description = '$description' WHERE id ='$id'";
}
// do the query
mysql_query($query) or die('Error, insert query failed');
echo "events list updated successfully!<br><br><a href='agenda.php'>add a new event</a>";
}
// ADD/EDIT FORM
else
{
// load stored values for editing event
if($action == 'edit')
{
$query = "SELECT * FROM events WHERE id='$id'";
$result = mysql_query($query);
$date = mysql_result($result,0,"date");
$time = mysql_result($result,0,"time");
$venue = mysql_result($result,0,"venue");
$description = mysql_result($result,0,"description");
$breedte = mysql_result($result,0,"breedte");
$hoogte = mysql_result($result,0,"hoogte");
$name = mysql_result($result,0,"flyerfront");
$name1 = mysql_result($result,0,"flyerback");
$month = substr($date, 5, 2);
$day = substr($date, 8, 2);
$year = substr($date, 0, 4);
$hour = realHour($time);
$minute = substr($time, 3, 2);
$ampm = realAMPM($time);
$showTime = mysql_result($result,0,"showTime");
}
?>
<form method="post" action="" enctype="multipart/form-data">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">Date</td>
<td>
<select name="month" id="month">
<option value="01" <?php if ($month == "01") {echo "selected";} ?>>Jan
<option value="02" <?php if ($month == "02") {echo "selected";} ?>>Feb
<option value="03" <?php if ($month == "03") {echo "selected";} ?>>Mar
<option value="04" <?php if ($month == "04") {echo "selected";} ?>>Apr
<option value="05" <?php if ($month == "05") {echo "selected";} ?>>May
<option value="06" <?php if ($month == "06") {echo "selected";} ?>>Jun
<option value="07" <?php if ($month == "07") {echo "selected";} ?>>Jul
<option value="08" <?php if ($month == "08") {echo "selected";} ?>>Aug
<option value="09" <?php if ($month == "09") {echo "selected";} ?>>Sep
<option value="10" <?php if ($month == "10") {echo "selected";} ?>>Oct
<option value="11" <?php if ($month == "11") {echo "selected";} ?>>Nov
<option value="12" <?php if ($month == "12") {echo "selected";} ?>>Dec
</select>
<select name="day" id="day">
<option value="01" <?php if ($day == "01") {echo "selected";} ?>>1
<option value="02" <?php if ($day == "02") {echo "selected";} ?>>2
<option value="03" <?php if ($day == "03") {echo "selected";} ?>>3
<option value="04" <?php if ($day == "04") {echo "selected";} ?>>4
<option value="05" <?php if ($day == "05") {echo "selected";} ?>>5
<option value="06" <?php if ($day == "06") {echo "selected";} ?>>6
<option value="07" <?php if ($day == "07") {echo "selected";} ?>>7
<option value="08" <?php if ($day == "08") {echo "selected";} ?>>8
<option value="09" <?php if ($day == "09") {echo "selected";} ?>>9
<option <?php if ($day == "10") {echo "selected";} ?>>10
<option <?php if ($day == "11") {echo "selected";} ?>>11
<option <?php if ($day == "12") {echo "selected";} ?>>12
<option <?php if ($day == "13") {echo "selected";} ?>>13
<option <?php if ($day == "14") {echo "selected";} ?>>14
<option <?php if ($day == "15") {echo "selected";} ?>>15
<option <?php if ($day == "16") {echo "selected";} ?>>16
<option <?php if ($day == "17") {echo "selected";} ?>>17
<option <?php if ($day == "18") {echo "selected";} ?>>18
<option <?php if ($day == "19") {echo "selected";} ?>>19
<option <?php if ($day == "20") {echo "selected";} ?>>20
<option <?php if ($day == "21") {echo "selected";} ?>>21
<option <?php if ($day == "22") {echo "selected";} ?>>22
<option <?php if ($day == "23") {echo "selected";} ?>>23
<option <?php if ($day == "24") {echo "selected";} ?>>24
<option <?php if ($day == "25") {echo "selected";} ?>>25
<option <?php if ($day == "26") {echo "selected";} ?>>26
<option <?php if ($day == "27") {echo "selected";} ?>>27
<option <?php if ($day == "28") {echo "selected";} ?>>28
<option <?php if ($day == "29") {echo "selected";} ?>>29
<option <?php if ($day == "30") {echo "selected";} ?>>30
<option <?php if ($day == "31") {echo "selected";} ?>>31
</select>
,
<select name="year" id="year">
<option <?php if ($year == (date('Y') - 3)) {echo "selected";} echo ">" . (date('Y') - 3); ?>
<option <?php if ($year == (date('Y') - 2)) {echo "selected";} echo ">" . (date('Y') - 2); ?>
<option <?php if ($year == (date('Y') - 1)) {echo "selected";} echo ">" . (date('Y') - 1); ?>
<option <?php if (($year == date('Y')) OR (!isset($year))) {echo "selected";} echo ">" . date('Y'); ?>
<option <?php if ($year == (date('Y') + 1)) {echo "selected";} echo ">" . (date('Y') + 1); ?>
<option <?php if ($year == (date('Y') + 2)) {echo "selected";} echo ">" . (date('Y') + 2); ?>
<option <?php if ($year == (date('Y') + 3)) {echo "selected";} echo ">" . (date('Y') + 3); ?>
<option <?php if ($year == (date('Y') + 4)) {echo "selected";} echo ">" . (date('Y') + 4); ?>
</select>
</td>
</tr>
<tr>
<td width="100">Venue</td>
<td>
<textarea name="venue" id="venue" rows="5" cols="80"><?php if (isset($venue)) {echo $venue;} ?></textarea>
</td>
</tr>
<tr>
<td width="100">Description</td>
<td>
<textarea name="description" id="description" rows="5" cols="80"><?php if (isset($description)) {echo $description;} ?></textarea>
</td>
</tr>
<tr>
<td width="100">Flyer Front </td>
<td><input type="file" name="pictures[0]" /><?php if (isset($name)) {echo $name;} ?></td>
</tr>
<tr>
<td>Flyer Back </td>
<td><input type="file" name="pictures[1]" /><?php if (isset($name1)) {echo $name1;} ?></td>
</tr>
<tr>
<td>Hoogte</td>
<td><input type="text" name="hoogte" id="hoogte" <?php if (isset($hoogte)) {echo "value=" . $hoogte;} ?>></td>
</tr>
<tr>
<td>Breedte</td>
<td><input type="text" name="breedte" id="breedte" <?php if (isset($breedte)) {echo "value=" . $breedte;} ?>></td>
</tr>
<tr>
<td> </td>
<td><?php
if ($action == 'edit')
{
echo "<input name='edit' type='submit' id='edit' value='update event'>";
}
else
{
echo "<input name='add' type='submit' id='add' value='add event'>";
}
?></td>
</tr>
</table>
</form>
<?php
}
?>
<table border="0" cellspacing="3">
<tr>
<td colspan="9" align="center" class="highlight">
UPCOMING EVENTS
</td>
</tr>
<?php
$query = "SELECT * FROM events ORDER BY date ASC";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
if ($row['date'] >= date('Y-m-d'))
{
displayEvents($row);
displayActions($row);
}
}
?>
</table>
<BR>
<BR>
<table border="0" cellspacing="3">
<tr>
<td colspan="9" align="center" class="highlight">
PAST EVENTS
</td>
</tr>
<?php
$query = "SELECT * FROM events ORDER BY date DESC";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
if ($row['date'] <= date('Y-m-d'))
{
displayEvents($row);
displayActions($row);
}
}
include '../closedb.php';
?>
</table>
</body>
</html>
Iemand een idee wat het probleem kan zijn?
Het script werkt wel prima alleen snap ik die melding niet.
Gewijzigd op 01/01/1970 01:00:00 door Lyrix Lyrix
Ik heb dit script ergens vandaan getoverd en toegevoegd aan me site
Op mijn eigen site werkt ie prima.
Alleen op een andere site dus niet, terwijl ik niets veranderd heb aan het script.
Waarom geeft ie dan toch die error terwijl het script prima werkt?
Hij upload en verplaatst netjes de bestanden zoals ik wil.