Jump to content

Problems with page form


malma

Recommended Posts

My page_form is not working, it show errors.

I have been trying to solve this problem but I have failed now i'm asking help from experts.

These are the errors

<br /><b>Notice</b>:  Undefined variable: sel_page in <b>C:\wamp\www\widget\page_form.php</b> on line <b>6</b><br />


<?php // this page is included by new_page.php and edit_page.php ?>
<?php if (!isset($new_page)) {$new_page = false;} ?>

<p>Page name: <input type="text" name="menu_name" value="<?php echo 
$sel_page['menu_name']; ?>" id="menu_name"/></p>
<p>Select 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>";
}
?></p>
</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
<input type="submit" value="Submit" />
</form>  
<br />
<a href="content.php">Cancel</a>
</p>
<p>Content: <br/>
<textarea name"content" rows"20" cols="80"><?php echo $sel_page['content']; ?>
</textarea>

</p>

I wonder why $sel_page gives me errors yet &sel_subject does not!!

 

Link to comment
Share on other sites

The error message says it all...

 

$sel_page hasn't been set before you've echoed it.  It's only a notice, so it's not the end of the world.  If this is on production, make sure you turn display_errors off in your php.ini (or use ini_set('display_errors', 0) if you don't have php.ini access).

 

So, simply put, in the the code you've included this file from, you've declared $sel_subject but you haven't declared $sel_page...

Link to comment
Share on other sites

Thanks for quick reply, unfotunately all error functions are turned on and I can't turn them off

These are the codes where I declared both $sel-subject and $sel_page.

<?php
function mysql_prep($value) {
    $magic_quotes_active = get_magic_quotes_gpc();
    $new_enough_php = function_exists( "mysql_real_escape_string");
    // i.e PHP >= v4.3.0
    if ($new_enough_php) { // PHP v4.3.0 or higher
    // undo any magic quotes effects so mysql_real_escape_string
    // can do the work
    if( $magic_quotes_active) { $value = stripslashes ( $value);}
    $value = mysql_real_escape_string( $value);
    } else {// before PHP v4.3.0
    // if magic quotes aren't already on then add slashes manually
    if (!$magic_quotes_active) {$value = addslashes($value);}
    // if magic quotes aren't active, the the slashes already exist
    }
    return $value;
    }

function redirect_to($location = NULL) {
    if ($location != NULL) {
        header("Location: {$location}");
        exit;
    }
}
    function confirm_query($result_set) {
    
  if(!$result_set) {
    die("Database query failed: " . mysql_error());
    }  
}
   function get_all_subjects() {
    global $connection;
    $query = "SELECT * 
        FROM subjects 
        ORDER BY position ASC";
    $subject_set = mysql_query($query, $connection);
    confirm_query($subject_set);
    return $subject_set;
   } 
   function get_all_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_subject_by_id($subject_id) {
    global $connection;
    $query = "
    SELECT *
     FROM subjects
     WHERE id = $subject_id
     LIMIT 1";
    $result_set = mysql_query($query, $connection);
    confirm_query($result_set);
    // REMEMBER:
    // if no rows are returned, fetch_array will return false
    if($subject = mysql_fetch_array($result_set)) {
    return $subject;
   }  else {
    return NULL;
   }
   }
    function get_page_by_id($page_id) {
    global $connection;
    $query = "
    SELECT *
     FROM pages
     WHERE id = $page_id
     LIMIT 1";
    $result_set = mysql_query($query, $connection);
    confirm_query($result_set);
    // REMEMBER:
    // if no rows are returned, fetch_array will return false
    if($page = mysql_fetch_array($result_set)) {
    return $page;
   }  else {
    return NULL;
   }
   }
   function find_selected_page() {
    global $sel_subject;
    global $sel_page;
   if (isset($_GET['subj'])) {
    $sel_subject = get_subject_by_id($_GET['subj']);
    $sel_page = null;
} elseif (isset($_GET['page'])) {
    $sel_subject = null;
    $sel_page = get_page_by_id($_GET['page']);
   
} else {
    $sel_subject = null; 
    $sel_page = null;
}
}

function navigation($sel_subject, $sel_page) {
  $output= "<ul class=\"subjects\">";

$subject_set = get_all_subjects();
while($subject = mysql_fetch_array($subject_set)){
                
  $output .= "<li";
    if ($subject['id'] ==$sel_subject['id']) {
    $output .= "class=\"selected\"";
    }
   $output .= "><a href=\"edit_subject.php?subj=" . 
urlencode($subject["id"]) ."\">{$subject['menu_name']}</a></li> ";
    
    $page_set = get_all_pages_for_subject($subject['id']);
    
   $output .= "<ul class=\"pages\">"; 
while($page = mysql_fetch_array($page_set)) {
    $output .= "<li";
    if ($page["id"]==$sel_page['id']) {
    $output .= "class=\"selected\"";
    }
    $output .= "><a href=\"content.php?page=" . 
urlencode($page["id"]). "\">{$page['menu_name']} </a></li>";
}
$output .= "</ul>";
  }
$output .= "</ul>"; 
  return $output;  
}
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.