nieuw item wordt niet goed in mysql gezet
Code:
Code (php)
1
2
2
$query = "INSERT INTO activiteiten (img_active, bericht, titel, active) VALUES ('".$weergeven."', '".$value."', '".$titel."', '".$actief."')";
$result = mysql_query($query) or die ("FOUT: " . mysql_error());
$result = mysql_query($query) or die ("FOUT: " . mysql_error());
Mysql :
Quote:
id,img,img_active,bericht,titel,active
Toe te voegen :
Quote:
img_active : 0
bericht : test bericht
titel : test titel
active : 1
bericht : test bericht
titel : test titel
active : 1
Wat er gebeurt :
Quote:
id = 5
img =
img_active = 0
bericht = test titel
titel = test titel
active = 1
img =
img_active = 0
bericht = test titel
titel = test titel
active = 1
Quote:
id = 6
img =
img_active = 0
bericht = test bericht
titel = test titel
active = 1
img =
img_active = 0
bericht = test bericht
titel = test titel
active = 1
Graag wat meer 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
<?
elseif ($_GET['actie'] == "nieuw" && $_GET['toepassen'] == "nee") {
?><br />
<div align="center">
<form enctype="multipart/form-data" action="activiteiten.php?actie=nieuw&toepassen=ja" method="POST">
<table width="600" border="0">
<tr>
<th colspan="2" scope="col">Activiteiten </th>
</tr>
<tr>
<td width="300">Titel :</td>
<td width="300"><input type="text" name="titel" maxlength="40" size="40" /> </td>
</tr>
<tr>
<td width="300">Afbeelding weergeven ?</td>
<td width="300"><INPUT TYPE="checkbox" NAME="active" VALUE="1"></td>
</tr>
<tr>
<td width="300">Afbeelding :</td>
<td width="300"><input type="file" name="afbeelding" /></td>
</tr>
<tr>
<td colspan="2">
<?php
// Include the CKEditor class.
include_once "ckeditor/ckeditor.php";
// The initial value to be displayed in the editor.
$initialValue = ($bericht);
// Create a class instance.
$CKEditor = new CKEditor();
// Path to the CKEditor directory, ideally use an absolute path instead of a relative dir.
// $CKEditor->basePath = '/ckeditor/'
// If not set, CKEditor will try to detect the correct path.
$CKEditor->basePath = 'ckeditor/';
// Create a textarea element and attach CKEditor to it.
$CKEditor->editor("editor1", $initialValue);
?>
</td>
</tr>
<tr>
<td colspan="2" ><br /><br /><div align="center"><input type="submit" value="Toevoegen"/></div><br /><br /></td>
</tr>
</table>
</form>
</div>
<?
}
//////////////////////////////////////////////Nieuw bericht toevoegen ////////////////////////////////////////////////////////////
elseif ($_GET['actie'] == "nieuw" && $_GET['toepassen'] == "ja") {
/////////////////////////////////////////////Nieuw bericht ZONDER foto ///////////////////////////////////////////////////////////
if (empty($_FILES['afbeelding']['name'])) {
$titel = mysql_real_escape_string($_POST['titel']);
$weergeven = mysql_real_escape_string($_POST['active']);
$actief = '1';
$postArray = &$_POST ; // 4.1.0 or later, use $_POST
foreach ( $postArray as $sForm => $value )
mysql_query("INSERT INTO activiteiten SET img = '', img_active = '".$weergeven."', bericht = '".$value."', titel = '".$titel."', active = '".$actief."' ") or die(mysql_error());
}
///////////////////////////////////////////Nieuw bericht MET foto //////////////////////////////////////////////////////////////
elseif (isset($_FILES['afbeelding']['name'])) {
$titel = mysql_real_escape_string($_POST['titel']);
$weergeven = mysql_real_escape_string($_POST['active']);
$actief = '1';
$postArray = &$_POST ; // 4.1.0 or later, use $_POST
foreach ( $postArray as $sForm => $value )
$target_path = "../upload/";
$target_path = $target_path . basename( $_FILES['afbeelding']['name']);
if(move_uploaded_file($_FILES['afbeelding']['tmp_name'], $target_path)) {
$fotoke = basename( $_FILES['afbeelding']['name']);
mysql_query("INSERT INTO activiteiten SET img = '".$fotoke."', img_active = '".$weergeven."', bericht = '".$value."', titel = '".$titel."', active = '".$actief."' ") or die(mysql_error());
}
}
}
//////////////////////////////////////////Einde//////////////////////////////////////////////////////////////////////////////
?>
elseif ($_GET['actie'] == "nieuw" && $_GET['toepassen'] == "nee") {
?><br />
<div align="center">
<form enctype="multipart/form-data" action="activiteiten.php?actie=nieuw&toepassen=ja" method="POST">
<table width="600" border="0">
<tr>
<th colspan="2" scope="col">Activiteiten </th>
</tr>
<tr>
<td width="300">Titel :</td>
<td width="300"><input type="text" name="titel" maxlength="40" size="40" /> </td>
</tr>
<tr>
<td width="300">Afbeelding weergeven ?</td>
<td width="300"><INPUT TYPE="checkbox" NAME="active" VALUE="1"></td>
</tr>
<tr>
<td width="300">Afbeelding :</td>
<td width="300"><input type="file" name="afbeelding" /></td>
</tr>
<tr>
<td colspan="2">
<?php
// Include the CKEditor class.
include_once "ckeditor/ckeditor.php";
// The initial value to be displayed in the editor.
$initialValue = ($bericht);
// Create a class instance.
$CKEditor = new CKEditor();
// Path to the CKEditor directory, ideally use an absolute path instead of a relative dir.
// $CKEditor->basePath = '/ckeditor/'
// If not set, CKEditor will try to detect the correct path.
$CKEditor->basePath = 'ckeditor/';
// Create a textarea element and attach CKEditor to it.
$CKEditor->editor("editor1", $initialValue);
?>
</td>
</tr>
<tr>
<td colspan="2" ><br /><br /><div align="center"><input type="submit" value="Toevoegen"/></div><br /><br /></td>
</tr>
</table>
</form>
</div>
<?
}
//////////////////////////////////////////////Nieuw bericht toevoegen ////////////////////////////////////////////////////////////
elseif ($_GET['actie'] == "nieuw" && $_GET['toepassen'] == "ja") {
/////////////////////////////////////////////Nieuw bericht ZONDER foto ///////////////////////////////////////////////////////////
if (empty($_FILES['afbeelding']['name'])) {
$titel = mysql_real_escape_string($_POST['titel']);
$weergeven = mysql_real_escape_string($_POST['active']);
$actief = '1';
$postArray = &$_POST ; // 4.1.0 or later, use $_POST
foreach ( $postArray as $sForm => $value )
mysql_query("INSERT INTO activiteiten SET img = '', img_active = '".$weergeven."', bericht = '".$value."', titel = '".$titel."', active = '".$actief."' ") or die(mysql_error());
}
///////////////////////////////////////////Nieuw bericht MET foto //////////////////////////////////////////////////////////////
elseif (isset($_FILES['afbeelding']['name'])) {
$titel = mysql_real_escape_string($_POST['titel']);
$weergeven = mysql_real_escape_string($_POST['active']);
$actief = '1';
$postArray = &$_POST ; // 4.1.0 or later, use $_POST
foreach ( $postArray as $sForm => $value )
$target_path = "../upload/";
$target_path = $target_path . basename( $_FILES['afbeelding']['name']);
if(move_uploaded_file($_FILES['afbeelding']['tmp_name'], $target_path)) {
$fotoke = basename( $_FILES['afbeelding']['name']);
mysql_query("INSERT INTO activiteiten SET img = '".$fotoke."', img_active = '".$weergeven."', bericht = '".$value."', titel = '".$titel."', active = '".$actief."' ") or die(mysql_error());
}
}
}
//////////////////////////////////////////Einde//////////////////////////////////////////////////////////////////////////////
?>
Toevoeging op 08/11/2012 22:11:58:
Ondertussen al weer uren aan het puzelen maar kom er niet uit. Hieronder de query die wordt uitgevoerd :
Quote:
INSERT INTO activiteiten SET img_active = '', bericht = 'fffffffff', titel = 'CMS zonder foto', active = '1'
Toevoeging op 08/11/2012 22:37:30:
Inmiddels is het gelukt, het was weer eens een stom probleem :) achter foreach ( $postArray as $sForm => $value ) moest nog een ; worden geplaatst en nu werkt het perfect.