Fout bij het opslaan van foto in databank
Ik ben een oud nieuwsscriptje aant vernieuwen, maar het werkt niet meer. Het lukt al om nieuws toe te voegen, bewerken en verwijderen. Maar in een nieuwsbericht moeten ook foto's geüpload worden en dit lukt me nog niet helemaal. Wanneer ik op de knop druk om een foto toe te voegen komt er de melding: "fout bij het vastleggen van de foto in de databank". Weet iemand hoe dit komt en wat ik er aan kan doen?
Alvast bedankt!
Hier is de code:
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
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
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($_POST['voegtoe']) {
$photoFileName = $_FILES['photo']['name']; // get client side file name
if ($photoFileName) { // file uploaded
$fileNameParts = explode(".", $photoFileName);
$fileExtension = end($fileNameParts); // part behind last dot
if ($fileExtension != "jpg" && $fileExtension != "JPEG" && $fileExtension != "JPG") {
die ("Kies aub een <b>jpg</b> foto, ga terug en probeer het opnieuw.");
}
$photoSize = $_FILES['photo']['size']; // size of uploaded file
if ($photoSize == 0) {
die ("Kies eerst een foto en klik daarna pas op \"voegtoe\", ga terug en probeer het opnieuw.");
}
// read photo
$tempFileName = $_FILES['photo']['tmp_name']; // temporary file at server side
$src_img = imagecreatefromjpeg ($tempFileName);
$width = imagesx($src_img); // get original source image width
$height = imagesy($src_img); // and height
// create small thumbnail
if (($height * 3) / 4 > $width) {
$dest_height = 260;
$dest_width = (260 * $width) / $height;
} else {
$dest_width = 200;
$dest_height = (200 * $height) / $width;
}
$dest_img = imagecreatetruecolor($dest_width, $dest_height);
$result = imagecopyresampled($dest_img, $src_img,0, 0, 0, 0, $dest_width, $dest_height,$width, $height); // resize the image
$indexke = strrpos($photoFileName, '.');
$photoFileName = substr ($photoFileName, 0, $indexke) . ".png";
imagepng($dest_img, "fotos_groot/thumbs/" . $photoFileName); // save image
imagepng($src_img, "fotos_groot/fotos/" . $photoFileName);
imagedestroy($src_img);
imagedestroy($dest_img);
mysql_query("INSERT INTO nieuws_fotos_groot (naam, height, width, height_groot, width_groot)
values ('$photoFileName', '$dest_height', '$dest_width', '$height', '$width')") or die ("fout bij het vastleggen van de foto in de databank");
}
}
}
if (isset($id)) {
$result = mysql_query("SELECT *
FROM nieuws_fotos_groot
WHERE id = '$id'");
$show_msg = mysql_fetch_array($result);
echo ( "<script language=\"javascript\" type=\"text/javascript\">\n<!--\n" .
"opener.document.submitform.bericht.value += \" [foto $show_msg[naam] width=$show_msg[width] height=$show_msg[height]]" . $id . "[/foto]\";\n" .
"window.close();\n" .
"// -->\n</script>\n");
// else show the form to submit new data:
} else {
?>
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($_POST['voegtoe']) {
$photoFileName = $_FILES['photo']['name']; // get client side file name
if ($photoFileName) { // file uploaded
$fileNameParts = explode(".", $photoFileName);
$fileExtension = end($fileNameParts); // part behind last dot
if ($fileExtension != "jpg" && $fileExtension != "JPEG" && $fileExtension != "JPG") {
die ("Kies aub een <b>jpg</b> foto, ga terug en probeer het opnieuw.");
}
$photoSize = $_FILES['photo']['size']; // size of uploaded file
if ($photoSize == 0) {
die ("Kies eerst een foto en klik daarna pas op \"voegtoe\", ga terug en probeer het opnieuw.");
}
// read photo
$tempFileName = $_FILES['photo']['tmp_name']; // temporary file at server side
$src_img = imagecreatefromjpeg ($tempFileName);
$width = imagesx($src_img); // get original source image width
$height = imagesy($src_img); // and height
// create small thumbnail
if (($height * 3) / 4 > $width) {
$dest_height = 260;
$dest_width = (260 * $width) / $height;
} else {
$dest_width = 200;
$dest_height = (200 * $height) / $width;
}
$dest_img = imagecreatetruecolor($dest_width, $dest_height);
$result = imagecopyresampled($dest_img, $src_img,0, 0, 0, 0, $dest_width, $dest_height,$width, $height); // resize the image
$indexke = strrpos($photoFileName, '.');
$photoFileName = substr ($photoFileName, 0, $indexke) . ".png";
imagepng($dest_img, "fotos_groot/thumbs/" . $photoFileName); // save image
imagepng($src_img, "fotos_groot/fotos/" . $photoFileName);
imagedestroy($src_img);
imagedestroy($dest_img);
mysql_query("INSERT INTO nieuws_fotos_groot (naam, height, width, height_groot, width_groot)
values ('$photoFileName', '$dest_height', '$dest_width', '$height', '$width')") or die ("fout bij het vastleggen van de foto in de databank");
}
}
}
if (isset($id)) {
$result = mysql_query("SELECT *
FROM nieuws_fotos_groot
WHERE id = '$id'");
$show_msg = mysql_fetch_array($result);
echo ( "<script language=\"javascript\" type=\"text/javascript\">\n<!--\n" .
"opener.document.submitform.bericht.value += \" [foto $show_msg[naam] width=$show_msg[width] height=$show_msg[height]]" . $id . "[/foto]\";\n" .
"window.close();\n" .
"// -->\n</script>\n");
// else show the form to submit new data:
} else {
?>
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
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
<script language="javascript" type="text/javascript">
<!--
function hidebuttons(theform)
{
document.body.style.cursor = "wait";
//if IE 4+ or NS 6+
if (document.all||document.getElementById)
{
//screen thru every element in the form, and hunt down "submit" and "reset"
for (i=0;i<theform.length;i++)
{
var tempobj=theform.elements[i]
try
{
if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
{
tempobj.style.display='none';
theform.elements[tempobj.name + "_hidden"].style.display="inline";
}
}
catch(errorObject) {}
}
}
}
// --->
</script>
<div align="center">
<table border="0" width="95%" cellspacing="0" cellpadding="0">
<tr>
<td class="tekst">
<br>
<div class="titel">Selecteer een foto</div>
</td>
</tr>
<tr>
<td bgcolor="#c0c0c0">
<img src="images/niks.gif" height="1" width="1" alt="">
</td>
</tr>
<tr>
<td class="tekst">
<div align="center">
<table border="0" cellspacing="15">
<tr>
<?php
$teller = 1;
$results = mysql_query("SELECT *
FROM nieuws_fotos_groot
WHERE id != '0'");
while($show_msg = mysql_fetch_array($results)) {
echo("<td align=\"center\"><table border=\"0\" cellspacing=\"2\" cellpadding=\"0\" bgcolor=\"#c0c0c0\"><tr><td><a href=\"foto_groot.php?id=$show_msg[id]&naam=$show_msg[naam]\"><img src=\"fotos_groot/thumbs/$show_msg[naam]\" width=\"$show_msg[width]\" height=\"$show_msg[height]\" border=\"0\" alt=\"klik om te selecteren\"></a></td></tr></table></td>\n");
if ($teller++ % 2 == 0)
echo ("</tr><tr>\n");
}
?>
</table>
<br>
<form onsubmit="hidebuttons(this)" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
<table border="0" bgcolor="#cccccc" cellspacing="1" cellpadding="0" width="95%">
<tr>
<td>
<table border="0" cellspacing="5" width="100%" bgcolor="#f6f6f6">
<tr>
<td>
<table border="0" cellspacing="5" width="100%">
<tr>
<td class="tekst" valign="top" colspan="3"><font size="-2">foto toevoegen<br><br></font>
</td>
</tr>
<tr>
<td class="tekst" valign="top"><b>Selecteer foto</b>
</td>
<td><input type="file" name="photo" class="formke" size="25" accept="image/jpeg"><br><br>
</td>
<td class="tekst" valign="top">
<input type="submit" value=" Voeg toe " class="form" name="voegtoe"><input type="button" value=" wacht even " class="form" name="voegtoe_hidden" disabled style="display:none">
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</form>
<input type="Button" value=" Cancel " class="form" OnClick="self.close();">
</td>
</tr>
</table>
</div>
<?php
}
mysql_close($connection);
?>
<!--
function hidebuttons(theform)
{
document.body.style.cursor = "wait";
//if IE 4+ or NS 6+
if (document.all||document.getElementById)
{
//screen thru every element in the form, and hunt down "submit" and "reset"
for (i=0;i<theform.length;i++)
{
var tempobj=theform.elements[i]
try
{
if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
{
tempobj.style.display='none';
theform.elements[tempobj.name + "_hidden"].style.display="inline";
}
}
catch(errorObject) {}
}
}
}
// --->
</script>
<div align="center">
<table border="0" width="95%" cellspacing="0" cellpadding="0">
<tr>
<td class="tekst">
<br>
<div class="titel">Selecteer een foto</div>
</td>
</tr>
<tr>
<td bgcolor="#c0c0c0">
<img src="images/niks.gif" height="1" width="1" alt="">
</td>
</tr>
<tr>
<td class="tekst">
<div align="center">
<table border="0" cellspacing="15">
<tr>
<?php
$teller = 1;
$results = mysql_query("SELECT *
FROM nieuws_fotos_groot
WHERE id != '0'");
while($show_msg = mysql_fetch_array($results)) {
echo("<td align=\"center\"><table border=\"0\" cellspacing=\"2\" cellpadding=\"0\" bgcolor=\"#c0c0c0\"><tr><td><a href=\"foto_groot.php?id=$show_msg[id]&naam=$show_msg[naam]\"><img src=\"fotos_groot/thumbs/$show_msg[naam]\" width=\"$show_msg[width]\" height=\"$show_msg[height]\" border=\"0\" alt=\"klik om te selecteren\"></a></td></tr></table></td>\n");
if ($teller++ % 2 == 0)
echo ("</tr><tr>\n");
}
?>
</table>
<br>
<form onsubmit="hidebuttons(this)" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
<table border="0" bgcolor="#cccccc" cellspacing="1" cellpadding="0" width="95%">
<tr>
<td>
<table border="0" cellspacing="5" width="100%" bgcolor="#f6f6f6">
<tr>
<td>
<table border="0" cellspacing="5" width="100%">
<tr>
<td class="tekst" valign="top" colspan="3"><font size="-2">foto toevoegen<br><br></font>
</td>
</tr>
<tr>
<td class="tekst" valign="top"><b>Selecteer foto</b>
</td>
<td><input type="file" name="photo" class="formke" size="25" accept="image/jpeg"><br><br>
</td>
<td class="tekst" valign="top">
<input type="submit" value=" Voeg toe " class="form" name="voegtoe"><input type="button" value=" wacht even " class="form" name="voegtoe_hidden" disabled style="display:none">
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</form>
<input type="Button" value=" Cancel " class="form" OnClick="self.close();">
</td>
</tr>
</table>
</div>
<?php
}
mysql_close($connection);
?>
Bouw nette foutafhandeling in en de 'echte' fout verschijnt op je scherm.
http://www.phphulp.nl/php/tutorial/data-verwerking/foutafhandeling-query-sql/735/
- SanThe - op 02/07/2012 16:35:47:
Dan is de query mislukt.
Bouw nette foutafhandeling in en de 'echte' fout verschijnt op je scherm.
http://www.phphulp.nl/php/tutorial/data-verwerking/foutafhandeling-query-sql/735/
Bouw nette foutafhandeling in en de 'echte' fout verschijnt op je scherm.
http://www.phphulp.nl/php/tutorial/data-verwerking/foutafhandeling-query-sql/735/
Oke, heb dat zonet toegepast met dit als resultaat:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Applications/MAMP/htdocs/Aikibudo News/foto_groot.php on line 127
[/quote]
Toevoeging op 02/07/2012 17:00:49:
Ik denk dat hier erges een fout zit:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
<?php
if (isset($id)) {
$result = mysql_query("SELECT *
FROM nieuws_fotos_groot
WHERE id = '$id'");
$show_msg = mysql_fetch_array($result);
echo ( "<script language=\"javascript\" type=\"text/javascript\">\n<!--\n" .
"opener.document.submitform.bericht.value += \" [foto $show_msg[naam] width=$show_msg[width] height=$show_msg[height]]" . $id . "[/foto]\";\n" .
"window.close();\n" .
"// -->\n</script>\n");
}
?>
if (isset($id)) {
$result = mysql_query("SELECT *
FROM nieuws_fotos_groot
WHERE id = '$id'");
$show_msg = mysql_fetch_array($result);
echo ( "<script language=\"javascript\" type=\"text/javascript\">\n<!--\n" .
"opener.document.submitform.bericht.value += \" [foto $show_msg[naam] width=$show_msg[width] height=$show_msg[height]]" . $id . "[/foto]\";\n" .
"window.close();\n" .
"// -->\n</script>\n");
}
?>
Gewijzigd op 02/07/2012 16:46:18 door Jos Vermassen
Wat je nu doet (uiteraard enkel tijdelijk, totdat het probleem is opgelost):
Code (php)
Je krijgt dan die query op je scherm te zien
Dan copy/paste je die query string in phpMyadmin; daar zal je een foutmelding krijgen (die wij van hieruit niet kunnen zien).
Gewijzigd op 02/07/2012 17:08:40 door Kris Peeters