My name is Carel and I am from South Africa and I could not find a place to introduce myself so I thought I will do it with my first post. Been a member for few months now, but never found it necessary to post, as I got quite a few of my answers from reading other posts.
I am doing a PHP course from the internet and ran into a little problem. I get what I assume is an infinite loop if I hit my "Edit Page" link.. It just shows the heading and background and then keeps on waiting for the local host.
I include code for the "content.php", "edit_page.php" and my "form_funtions.php" pages. If you need more, please let me know.
Not included is the code for "connections.php" and "functions.php" as it gives no errors on the other pages.
What I can also mention is that if I test the page "edit_page.php" in my browser directly from my code editor it goes to "content.php", like it says on line 6.
Thank you so long in advance for you trouble looking at my code.
Carelkat
Here is the code for content.php
- Code: Select all
<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php find_selected_page(); ?>
<?php include("includes/header.php"); ?>
<table id="structure">
<tr>
<td id="navigation">
<?php echo navigation($sel_subject, $sel_page); ?>
<br />
<a href="new_subject.php">+ Add a new subject</a>
</td>
<td id="page">
<?php if (!is_null($sel_subject)) { //subject selected} ?>
<h2><?php echo $sel_subject['menu_name']; ?></h2>
<?php } elseif (!is_null($sel_page)) { //page selected} ?>
<h2><?php echo $sel_page['menu_name']; ?></h2>
<div class="page-content">
<?php echo $sel_page['content']; ?>
</div>
<br />
<a href="edit_page.php?page=<?php echo urlencode($sel_page['id']); ?>">Edit page</a>
<?php } else { //nothing selected ?>
<h2>Select a subject or a page to edit</h2>
<?php } ?>
</td>
</tr>
</table>
<?php
require("includes/footer.php"); ?>
and for edit_page.php
- Code: Select all
<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php
//Maak seker die subject id word gestuur as 'n interger
if (intval($_GET['page']) == 0) {
redirect_to('content.php');
}
include_once("includes/form_functions.php");
//BEGIN FORM PROCESSING
//begin slegs as die form gesubmit is.
if (isset($_POST['submit'])){
//begin 'n array om ons foute te hou.
$errors = array();
}
//begin validations op die form data
$required_fields = array('menu_name', 'position', 'visible', 'content');
$errors = array_merge((array)$errors, check_required_fields((array)$required_fields));
$fields_with_lengths = array('menu_name' => 30);
$errors = array_merge((array)$errors, check_max_field_lengths((array)$fields_with_lengths));
//maak form data skoon voor dit in db ingesit word.
$id = mysql_prep($_GET['page']);
$menu_name = trim(mysql_prep($_POST['menu_name']));
$position = mysql_prep($_POST['position']);
$visible = mysql_prep($_POST['visible']);
$content = mysql_prep($_POST['content']);
//word slegs in die databasis ingesit as dit skoon is
if (empty($errors)){
$query = "UPDATE pages SET
menu_name = '{$menu_name}',
position = {$position},
visible = {$visible}
content = '{$content}'
WHERE id = {$id}";
$result = mysql_query($query);
//toets om te sien update suksesvol was.
if (mysql_affected_rows() ==1) {
//suksesvol
$message = "Die bladsy is suksesvol verander.";
} else {
$message = "Die bladsy is nie suksesvol verander nie.";
$message .= "<br />" . mysql_error(); }
} else {
if (count($errors) == 1){
$message = "Daar was 1 fout in die form";
} else {
$message = "Daar was" . count($errors) . "in die form.";
}
}
//Einde van form proseseering.
?>
<?php find_selected_page(); ?>
<?php include("includes/header.php"); ?>
<table id="structure">
<tr>
<td id="navigation">
<?php echo navigation($sel_subject, $sel_page); ?>
<br />
<a href="new_subject.php">+ Add a new subject</a>
</td>
<td id="page">
<h2>Edit page: <?php echo $sel_page['menu_name']; ?></h2>
<?php if (!empty($message)) {echo "<p class=\"message\">" . $message .
"</p>";} ?>
<?php if (!empty($errors)) {display_errors($errors);} ?>
<form action="edit_page.php?page=<?php echo $sel_page['id']; ?>" method="post">
<?php include "page_form.php" ?>
<input type="submit" name="submit" value="Update Page" /> &bsp;
<a href="delete_page.php?page=<?php echo $sel_page['id']; ?>"
onclick="return confirm('Are you sure you want to delete this page?');">
Delete page</a>
</form>
<br />
<a href="content.php?page=<?php echo $sel_page['id']; ?>">Cancel</a> <br />
</td>
</tr>
</table>
and for form_functions.php
- Code: Select all
<?php
function check_required_fields($required_array) {
$field_errors = array();
foreach($required_array as $fieldname) {
if (!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) &&
$_POST[$fieldname] = 0)) {
$field_errors[] = $fieldname;
}
}
return $field_errors;
}
function check_max_field_lengths($field_length_array) {
$field_errors = array();
foreach($field_length_array as $fieldname => $maxlength) {
if (strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) {
$field_errors[] = $fieldname; }
}
return $field_errors;
}
function display_errors($error_array) {
echo "<p class=\"errors\">";
echo "Kyk asseblief na die volgende velde: <br />";
foreach($error_array as $error) {
echo " - " . $error . "<br />";
}
echo "</p>";
}
?>



