Foto toevoegen werkt niet
Enigste probleem ik krijg een foutmelding en ik denk dat de fout ergens in m'n code zit om een foto te uploaden maar ik weet niet waar.
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
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
<?php
/******************
*Initialisatie
*******************/
$_srv = $_SERVER['PHP_SELF'];
/******************
* autoload
******************/
function __autoload($className) {
require_once "../klassen/$className.class.php";
}
include("../connections/pdo.inc.php");
include("../php_lib/inlezen.inc.php");
include("../php_lib/menu.inc.php");
include("../php_lib/gemeente.inc.php");
try
{
// toon formulier
if (! isset($_POST["submit"])) // geen formulier
{
$_output .= "<h1>Auto toevoegen</h1>
<form method='post' action='$_srv' enctype='multipart/form-data'><table class='levtoev'>";
$_output.= "
<tr><td><label>Code:</label></td><td><input type='text' name='Code'/></td></tr>";
//Merkenlijst bv Opel
$_resultmerk = $_PDO -> query("select * from t_merken;");
if ($_resultmerk -> rowCount() > 0)
{
$_output.= "<tr><td><label>Merk: </label></td><td><select name='Merk'>";
while ($_row = $_resultmerk -> fetch(PDO::FETCH_ASSOC))
{
$_output.= "<option value=" .$_row['d_Merk'].">" .$_row['d_Merknaam'] . "</option>";
}
$_output.= "</select></td></tr>";
}
//Typelijst bv Astra
$_resulttype = $_PDO -> query("select * from t_typen;");
if ($_resulttype -> rowCount() > 0)
{
$_output.= "<tr><td><label>Type:</label></td><td><select name='Type'>";
while ($_row = $_resulttype -> fetch(PDO::FETCH_ASSOC))
{
$_output.= "<option value=" .$_row['d_Typeid'].">" .$_row['d_Typenaam'] . "</option>";
}
$_output.= "</select></td></tr>";
}
//Categorie kiezen bv Break
$_resultcategorie = $_PDO -> query("select * from t_categorie;");
if ($_resultcategorie -> rowCount() > 0)
{
$_output.= "<tr><td><label>Categorie:</label></td><td><select name='Categorie'>";
while ($_row = $_resultcategorie -> fetch(PDO::FETCH_ASSOC))
{
$_output.= "<option value=" .$_row['d_Categorie'].">" .$_row['d_Catnaam'] . "</option>";
}
$_output.= "</select></td></tr>";
}
//Bouwjaar bv 2013
$_resultjaar = $_PDO -> query("select * from t_bouwjaar;");
if ($_resultjaar -> rowCount() > 0)
{
$_output.= "<tr><td><label>Bouwjaar:</label></td><td><select name='Bouwjaar'>";
while ($_row = $_resultjaar -> fetch(PDO::FETCH_ASSOC))
{
$_output.= "<option value=" .$_row['d_ID'].">" .$_row['d_Bjaar'] . "</option>";
}
$_output.= "</select></td></tr>";
}
$_output.= "<tr><td><label>Uitvoering</label></td><td><input type='text' name='Uitvoering'/></td></tr>";
//Leverancier
$_resultlev = $_PDO -> query("select * from t_leveranciers;");
if ($_resultlev -> rowCount() > 0)
{
$_output.= "<tr><td><label>Leverancier:</label></td><td><select name='Leverancier'>";
while ($_row = $_resultlev -> fetch(PDO::FETCH_ASSOC))
{
$_output.= "<option value=" .$_row['d_ID'].">" .$_row['d_Bedrijf'] . "</option>";
}
$_output.= "</select></td></tr>";
}
$_output.= "<tr><td><label>Voorraad</label></td><td><input type='number' name='Voorraad' size='5' min='1'/></td></tr>
<tr><td><label>Omschrijving</label></td><td><input type='text' name='Omschrijving'/></td></tr>
<tr><td><label>Foto</label></td><td><input type='file' id='foto' name='Foto'/></td></tr>
<tr><td><label>Prijs</label></td><td><input type='number' name='Prijs'/></td></tr>";
$_resultbtw = $_PDO -> query("select * from t_btw;");
if ($_resultbtw -> rowCount() > 0)
{
$_output.= "<tr><td><label>BTW</label></td><td><select name='Btw'>";
while ($_row = $_resultbtw -> fetch(PDO::FETCH_ASSOC))
{
$_btwpct = $_row['d_BTWAanslag'] * 100;
$_output.= "<option value=" .$_row['d_BTWCode'].">" .$_btwpct . "% </option>";
}
$_output.= "</select></td></tr></table>";
}
$_output.= "</table><input name='submit' type='submit' value='verzenden'>
</form>";
}
else
{
if (!isset($_POST["$_srv"])){
$_code =$_POST["Code"];
$_merk =$_POST["Merk"];
$_type =$_POST["Type"];
$_uitvoering =$_POST["Uitvoering"];
$_categorie =$_POST["Categorie"];
$_omschrijving =$_POST["Omschrijving"];
$_voorraad =$_POST["Voorraad"];
$_prijs =$_POST["Prijs"];
$_btw =$_POST["Btw"];
$_leverancier =$_POST["Leverancier"];
$_bouwjaar =$_POST["Bouwjaar"];
$oFile = new FileUpload($_FILES['Foto']);
$oFile->addFileType('jpg', array('image/jpeg','image/pjpeg'));
$oFile->move('../images');
if (empty($_FILES['logo']['name'])) {
$_foto = "../images/default.jpg";
}else{
$_foto = "../images/" . basename($_FILES['Foto']['name']);
}
// query
{
$_resultOK = $_PDO -> query("INSERT INTO t_auto(d_Code, d_Merk, d_Type, d_Uitvoering, d_Categorie, d_Omschrijving, d_Voorraad, d_Prijs_ex, d_BTW, d_Leverancier, d_bouwjaar, d_Foto) VALUES ('$_code','$_merk','$_type','$_uitvoering','$_categorie','$_bouwjaar','$_leverancier','$_voorraad','$_omschrijving','$_foto','$_prijs','$_btw');");
$_output = "Auto toegevoegd.";
}
}
}
// Object instantieren
$_smarty = new My_smarty();
// We kennen de variabelen toe
$_smarty->assign('menuh',menu('A'));
$_smarty->assign('menuv',menu(1));
$_smarty->assign('inhoud', $_output);
// display it
$_smarty->display('autolev.tpl');
}
catch (myException $e)
{
log("../log/logfile.csv");
errorMessage();
}
?>
/******************
*Initialisatie
*******************/
$_srv = $_SERVER['PHP_SELF'];
/******************
* autoload
******************/
function __autoload($className) {
require_once "../klassen/$className.class.php";
}
include("../connections/pdo.inc.php");
include("../php_lib/inlezen.inc.php");
include("../php_lib/menu.inc.php");
include("../php_lib/gemeente.inc.php");
try
{
// toon formulier
if (! isset($_POST["submit"])) // geen formulier
{
$_output .= "<h1>Auto toevoegen</h1>
<form method='post' action='$_srv' enctype='multipart/form-data'><table class='levtoev'>";
$_output.= "
<tr><td><label>Code:</label></td><td><input type='text' name='Code'/></td></tr>";
//Merkenlijst bv Opel
$_resultmerk = $_PDO -> query("select * from t_merken;");
if ($_resultmerk -> rowCount() > 0)
{
$_output.= "<tr><td><label>Merk: </label></td><td><select name='Merk'>";
while ($_row = $_resultmerk -> fetch(PDO::FETCH_ASSOC))
{
$_output.= "<option value=" .$_row['d_Merk'].">" .$_row['d_Merknaam'] . "</option>";
}
$_output.= "</select></td></tr>";
}
//Typelijst bv Astra
$_resulttype = $_PDO -> query("select * from t_typen;");
if ($_resulttype -> rowCount() > 0)
{
$_output.= "<tr><td><label>Type:</label></td><td><select name='Type'>";
while ($_row = $_resulttype -> fetch(PDO::FETCH_ASSOC))
{
$_output.= "<option value=" .$_row['d_Typeid'].">" .$_row['d_Typenaam'] . "</option>";
}
$_output.= "</select></td></tr>";
}
//Categorie kiezen bv Break
$_resultcategorie = $_PDO -> query("select * from t_categorie;");
if ($_resultcategorie -> rowCount() > 0)
{
$_output.= "<tr><td><label>Categorie:</label></td><td><select name='Categorie'>";
while ($_row = $_resultcategorie -> fetch(PDO::FETCH_ASSOC))
{
$_output.= "<option value=" .$_row['d_Categorie'].">" .$_row['d_Catnaam'] . "</option>";
}
$_output.= "</select></td></tr>";
}
//Bouwjaar bv 2013
$_resultjaar = $_PDO -> query("select * from t_bouwjaar;");
if ($_resultjaar -> rowCount() > 0)
{
$_output.= "<tr><td><label>Bouwjaar:</label></td><td><select name='Bouwjaar'>";
while ($_row = $_resultjaar -> fetch(PDO::FETCH_ASSOC))
{
$_output.= "<option value=" .$_row['d_ID'].">" .$_row['d_Bjaar'] . "</option>";
}
$_output.= "</select></td></tr>";
}
$_output.= "<tr><td><label>Uitvoering</label></td><td><input type='text' name='Uitvoering'/></td></tr>";
//Leverancier
$_resultlev = $_PDO -> query("select * from t_leveranciers;");
if ($_resultlev -> rowCount() > 0)
{
$_output.= "<tr><td><label>Leverancier:</label></td><td><select name='Leverancier'>";
while ($_row = $_resultlev -> fetch(PDO::FETCH_ASSOC))
{
$_output.= "<option value=" .$_row['d_ID'].">" .$_row['d_Bedrijf'] . "</option>";
}
$_output.= "</select></td></tr>";
}
$_output.= "<tr><td><label>Voorraad</label></td><td><input type='number' name='Voorraad' size='5' min='1'/></td></tr>
<tr><td><label>Omschrijving</label></td><td><input type='text' name='Omschrijving'/></td></tr>
<tr><td><label>Foto</label></td><td><input type='file' id='foto' name='Foto'/></td></tr>
<tr><td><label>Prijs</label></td><td><input type='number' name='Prijs'/></td></tr>";
$_resultbtw = $_PDO -> query("select * from t_btw;");
if ($_resultbtw -> rowCount() > 0)
{
$_output.= "<tr><td><label>BTW</label></td><td><select name='Btw'>";
while ($_row = $_resultbtw -> fetch(PDO::FETCH_ASSOC))
{
$_btwpct = $_row['d_BTWAanslag'] * 100;
$_output.= "<option value=" .$_row['d_BTWCode'].">" .$_btwpct . "% </option>";
}
$_output.= "</select></td></tr></table>";
}
$_output.= "</table><input name='submit' type='submit' value='verzenden'>
</form>";
}
else
{
if (!isset($_POST["$_srv"])){
$_code =$_POST["Code"];
$_merk =$_POST["Merk"];
$_type =$_POST["Type"];
$_uitvoering =$_POST["Uitvoering"];
$_categorie =$_POST["Categorie"];
$_omschrijving =$_POST["Omschrijving"];
$_voorraad =$_POST["Voorraad"];
$_prijs =$_POST["Prijs"];
$_btw =$_POST["Btw"];
$_leverancier =$_POST["Leverancier"];
$_bouwjaar =$_POST["Bouwjaar"];
$oFile = new FileUpload($_FILES['Foto']);
$oFile->addFileType('jpg', array('image/jpeg','image/pjpeg'));
$oFile->move('../images');
if (empty($_FILES['logo']['name'])) {
$_foto = "../images/default.jpg";
}else{
$_foto = "../images/" . basename($_FILES['Foto']['name']);
}
// query
{
$_resultOK = $_PDO -> query("INSERT INTO t_auto(d_Code, d_Merk, d_Type, d_Uitvoering, d_Categorie, d_Omschrijving, d_Voorraad, d_Prijs_ex, d_BTW, d_Leverancier, d_bouwjaar, d_Foto) VALUES ('$_code','$_merk','$_type','$_uitvoering','$_categorie','$_bouwjaar','$_leverancier','$_voorraad','$_omschrijving','$_foto','$_prijs','$_btw');");
$_output = "Auto toegevoegd.";
}
}
}
// Object instantieren
$_smarty = new My_smarty();
// We kennen de variabelen toe
$_smarty->assign('menuh',menu('A'));
$_smarty->assign('menuv',menu(1));
$_smarty->assign('inhoud', $_output);
// display it
$_smarty->display('autolev.tpl');
}
catch (myException $e)
{
log("../log/logfile.csv");
errorMessage();
}
?>
Bert Van den Brande op 02/03/2013 16:51:26:
ik krijg een foutmelding
En die foutmelding is.... ? Meestal staat daar ook precies de regel bij waar de foutmelding zich voor doet overigens.
Wat is dat dan?
Waarom PHP_SELF (die niet veilig is), onnodig kopieren en dat als $_POST["..."] gebruiken?
Waarom niet gewoon $_POST[$_SERVER['PHP_SELF']]?
Serverfout
Er is een fout opgetreden toen de website http://bert.sna-webo.be/scripts/a_toevoegen.php probeerde op te halen. De server kan offline zijn wegens onderhoud of kan onjuist zijn geconfigureerd.
Hier zijn enkele suggesties:
Laad deze webpagina later opnieuw.
Toevoeging op 03/03/2013 00:21:24:
@ Eddy, omdat ik da ni ken :-) ben nog ni lang bezig me PHP