Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post PHP form visibility, using lynda.com video.

    Hi people, pls i need ur help, am using the lynda.com video, my visible form is still not working. the intructor resolved his by adding the text in blue to this initial line of text.
    if (!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && !is_int($_POST[$fieldname])))

    He said i can either add && !is_int($_POST[$fieldname])[/COLOR])) or use something else to test instead of empty, pls what else can i use instead of empty..

    Note: i went further by ignoring the visible,but my adding new page did not come up, guess that could have caused it.

    Will appreciate ur reply.

    here is the whole edit_subject page code below.

    <?php require_once("includes/connection.php"); ?>
    <?php require_once("includes/functions.php"); ?>
    <?php
    if (intval($_GET['subj']) == 0) {
    redirect_to("content.php");
    }
    if (isset($_POST['submit'])) {
    $errors = array();

    $required_fields = array('menu_name', 'position');
    foreach($required_fields as $fieldname) {
    if (!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && !is_int($_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)) {
    //perform update
    $id = mysql_prep($_GET['subj']);
    $menu_name = mysql_prep($_POST['menu_name']);
    $position = mysql_prep($_POST['position']);

    $query = "UPDATE subjects SET
    menu_name = '{$menu_name}',
    position = {$position}
    WHERE id = {$id}";
    $result = mysql_query($query, $connection);
    if (mysql_affected_rows() == 1) {
    // Success
    $message = "The subject was succesfully updated.";
    } else {
    // Failed
    $message = "The subject update failed.";
    $message .= "<br />". mysql_error();
    }
    } else {
    // Errors occurred
    $message = "There were " . count($errors) . " errors in the form";
    }

    } // end: if (isset($_POST['submit']))
    ?>
    <?php find_selected_page(); ?>
    <?php include("includes/header.php"); ?>
    <table id="structure">
    <tr>
    <td id="navigation">
    <?php echo navigation($sel_subject, $sel_page); ?>
    </td>
    <td id="page">
    <h2>Edit Subject: <?php echo $sel_subject['menu_name']; ?></h2>
    <?php if (!empty($message)) {
    echo "<p class=\"message\">" . $message . "</p>";
    } ?>
    <?php
    // output a list of the field that had errors
    if (!empty($errors)) {
    echo "<p class=\"errors\">";
    echo " Please review the following fields: <br />";
    foreach($errors as $error) {
    echo " - " . $error . "<br />";
    }
    echo "</p>";
    }
    ?>
    <form action="edit_subject.php?subj=<?php echo urlencode($sel_subject['id']); ?>" method="post">
    <p>Subject name:
    <input type="text" name="menu_name" value="<?php echo $sel_subject['menu_name']; ?>" id="menu_name" />
    </p>
    <p>Position:
    <select name="position">
    <?php
    $subject_set = get_all_subjects();
    $subject_count = mysql_num_rows($subject_set);
    // $subject_count + 1 bcos we are adding a subject
    for($count=1; $count <= $subject_count+1; $count++) {
    echo "<option value=\"{$count}\"";
    if ($sel_subject['position'] == $count) {
    echo " selected";
    }
    echo ">{$count}</option>";
    }
    ?>
    </select>
    </p>
    <input type="submit" name="submit" value="Edit Subject" />

    &nbsp;&nbsp;
    <a href="delete_subject.php?subj=<?php echo urlencode($sel_subject['id']); ?>" onClick="return confirm('Are you sure?');">Delete Subject</a>
    </form>
    <br />
    <a href="content.php">Cancel</a>
    <div style="margin-top: 2em; border-top: 1px solid #000000;">
    <h3>Pages in this subject:</h3>
    <ul>
    <?php
    $subject_pages = get_pages_for_subject($sel_subject['id']);
    while($page = mysql_fetch_array($subject_pages)) {
    echo "<li><a href=\"content.php?page={$page['id']}\">
    {$page['menu_name']}</a></li>";
    }
    ?>
    </ul>
    <br />
    + <a href="new_page.php?subj=<?php echo $sel_subject['id']; ?>">Add
    a new page to this subject</a>
    </div>
    </td>
    </tr>
    </table>
    <?php require("includes/footer.php"); ?>

    Thanks Taiwo

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    holy code dump, WRAP YOUR CODE. why would you post all of this is your question was only about how to test if a string is empty?

    another method to test if it's empty:

    PHP Code:
    && trim($_POST[$fieldname]) <> "" 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •