Nieuwe pagina toevoegen
Wanneer ik een pagina wil toevoegen aan het menu via een knop, werkt dit niet. Er zijn geen errors, de zogezegde pagina komt wel in de databank te staan maar niet in het menu zelf.
Hoe komt dit?
-----> create_page.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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
<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php
$errors = array();
$required_fields = array('menu_name', 'position', 'visible', 'content');
foreach($required_fields as $fieldname) {
if(!isset($_POST[$fieldname]) || empty($_POST[$fieldname])) {
$errors[] = $fieldname;
}
}
$fields_with_lengths = array('menu_name' =>30);
foreach($fields_with_lengths as $fieldname => $maxlength) {
if(strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) {
$errors[] = $fieldname;
}
}
if(!empty($errors)) {
redirect_to('new_page.php');
}
?>
<?php
$menu_name = mysql_prep($_POST['menu_name']);
$position = mysql_prep($_POST['position']);
$visible = mysql_prep($_POST['visible']);
$content = mysql_prep($_POST['content']);
?>
<?php
$query = "INSERT INTO pages (
menu_name, position, visible, content
) VALUES (
'{$menu_name}', {$position}, {$visible}, '{$content}'
)";
$result = mysql_query($query, $connection);
if($result) {
redirect_to('content.php');
} else {
echo "<p>Page creation failed.</p>";
echo "<p>" . mysql_error() . "</p>";
}
?>
<?php mysql_close($connection); ?>
-----> new_page.php <-----
<?php require_once("includes/functions.php"); ?>
<?php require_once("includes/connection.php"); ?>
<?php find_selected_page(); ?>
<?php include("includes/header.php"); ?>
<?php if(!isset($new_page)) { $new_page = false; } ?>
<table id="structure">
<tr>
<td id="navigation">
<?php echo navigation($sel_subject, $sel_page); ?>
</td>
<td id="page">
<h2>Add new page</h2>
<?php if(!empty($message)) { echo "<p class=\"message\">" . $message .
"</p>"; } ?>
<?php if(!empty($errors)) { display_errros($errors); } ?>
<form action="create_page.php?subj=<?php echo $sel_page['id']; ?>" method="post">
<?php $new_page = true; ?>
<p>Page name:
<input type="text" name="menu_name" value="" id="menu_name" />
</p>
<p>Position:
<select name="position">
<?php
if(!$new_page) {
$page_set = get_pages_for_subject($sel_page['subject_id']);
$page_count = mysql_num_rows($page_set);
} else {
$page_set = get_pages_for_subject($sel_subject['id']);
$page_count = mysql_num_rows($page_set) + 1;
}
for($count=1; $count <= $page_count; $count++) {
echo "<option value=\"{$count}\"";
if($sel_page['position'] == $count) { echo " selected"; }
echo ">{$count}</option>";
}
?>
</select>
</p>
<p>Visible:
<input type="radio" name="visible" value="0"<?php if($sel_page['visible'] == 0) { echo " checked"; }
?> /> No
<input type="radio" name="visible" value="1"<?php
if($sel_page['visible'] == 1) { echo " checked"; }
?> /> Yes
</p>
<p>Content:<br />
<textarea name="content" rows="20" cols="80"><?php echo $sel_page['content'];
?></textarea>
</p>
<input type="submit" name="submit" value"Add Page" />
</form>
<br />
<a href="edit_subject.php?subj=<?php echo $sel_subject['id'];
?>">Cancel</a><br />
</td>
</tr>
</table>
<?php require("includes/footer.php"); ?>
[/CODE]
<?php require_once("includes/functions.php"); ?>
<?php
$errors = array();
$required_fields = array('menu_name', 'position', 'visible', 'content');
foreach($required_fields as $fieldname) {
if(!isset($_POST[$fieldname]) || empty($_POST[$fieldname])) {
$errors[] = $fieldname;
}
}
$fields_with_lengths = array('menu_name' =>30);
foreach($fields_with_lengths as $fieldname => $maxlength) {
if(strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) {
$errors[] = $fieldname;
}
}
if(!empty($errors)) {
redirect_to('new_page.php');
}
?>
<?php
$menu_name = mysql_prep($_POST['menu_name']);
$position = mysql_prep($_POST['position']);
$visible = mysql_prep($_POST['visible']);
$content = mysql_prep($_POST['content']);
?>
<?php
$query = "INSERT INTO pages (
menu_name, position, visible, content
) VALUES (
'{$menu_name}', {$position}, {$visible}, '{$content}'
)";
$result = mysql_query($query, $connection);
if($result) {
redirect_to('content.php');
} else {
echo "<p>Page creation failed.</p>";
echo "<p>" . mysql_error() . "</p>";
}
?>
<?php mysql_close($connection); ?>
-----> new_page.php <-----
<?php require_once("includes/functions.php"); ?>
<?php require_once("includes/connection.php"); ?>
<?php find_selected_page(); ?>
<?php include("includes/header.php"); ?>
<?php if(!isset($new_page)) { $new_page = false; } ?>
<table id="structure">
<tr>
<td id="navigation">
<?php echo navigation($sel_subject, $sel_page); ?>
</td>
<td id="page">
<h2>Add new page</h2>
<?php if(!empty($message)) { echo "<p class=\"message\">" . $message .
"</p>"; } ?>
<?php if(!empty($errors)) { display_errros($errors); } ?>
<form action="create_page.php?subj=<?php echo $sel_page['id']; ?>" method="post">
<?php $new_page = true; ?>
<p>Page name:
<input type="text" name="menu_name" value="" id="menu_name" />
</p>
<p>Position:
<select name="position">
<?php
if(!$new_page) {
$page_set = get_pages_for_subject($sel_page['subject_id']);
$page_count = mysql_num_rows($page_set);
} else {
$page_set = get_pages_for_subject($sel_subject['id']);
$page_count = mysql_num_rows($page_set) + 1;
}
for($count=1; $count <= $page_count; $count++) {
echo "<option value=\"{$count}\"";
if($sel_page['position'] == $count) { echo " selected"; }
echo ">{$count}</option>";
}
?>
</select>
</p>
<p>Visible:
<input type="radio" name="visible" value="0"<?php if($sel_page['visible'] == 0) { echo " checked"; }
?> /> No
<input type="radio" name="visible" value="1"<?php
if($sel_page['visible'] == 1) { echo " checked"; }
?> /> Yes
</p>
<p>Content:<br />
<textarea name="content" rows="20" cols="80"><?php echo $sel_page['content'];
?></textarea>
</p>
<input type="submit" name="submit" value"Add Page" />
</form>
<br />
<a href="edit_subject.php?subj=<?php echo $sel_subject['id'];
?>">Cancel</a><br />
</td>
</tr>
</table>
<?php require("includes/footer.php"); ?>
[/CODE]
Gewijzigd op 14/01/2012 16:27:46 door Jos Vermassen
Zie nergens een SELECT query --> hoe worden de gegevens opgehaald om getoond te worden?
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
<?php
function get_pages_for_subject($subject_id) {
global $connection;
$query = "SELECT *
FROM pages
WHERE subject_id = {$subject_id}
ORDER BY position ASC";
$page_set = mysql_query($query, $connection);
confirm_query($page_set);
return $page_set;
}
?>
function get_pages_for_subject($subject_id) {
global $connection;
$query = "SELECT *
FROM pages
WHERE subject_id = {$subject_id}
ORDER BY position ASC";
$page_set = mysql_query($query, $connection);
confirm_query($page_set);
return $page_set;
}
?>
Gewijzigd op 14/01/2012 17:16:13 door Jos Vermassen
Waarom open en sluit je de code? dit is nergens voor nodig.