Submit Your Article Forum Rules

Results 1 to 10 of 16

Thread: Getting error when submitting 'visible' field to database with php

Threaded View

  1. #1
    Senior Member ristenk1's Avatar
    Join Date
    Apr 2009
    Posts
    122

    Getting error when submitting 'visible' field to database with php

    I am new to php... I am actually trying to walk myself through a Lynda tutorial and have come up on a hang up I can't figure out The code below works on everything EXCEPT when I try to make submit Visible - No. It doesn't update and says there is an error in my visibility field. If I go into the database and change all of the pages to no (changing the visibility field to zero for all of the fields), I can then use the form and successfully change the Visibility to Yes when submitting the form. I don't know why the visibility is working when I submit - yes (one) and not working when I submit - no (zero)... please can someone help me?

    Code of edit_page.php:


    //clean up the form data before putting it in the database
    $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']);

    //Database submission only proceeds if there were NO errors.
    if(empty($errors)) {
    $query = "UPDATE pages SET
    menu_name = '{$menu_name}',
    position = {$position},
    visible = {$visible},
    content = '{$content}'
    WHERE id = {$id}"
    ;
    $result = mysql_query($query, $connection);

    //test to see if the update occurred
    if(mysql_affected_rows() == 1) {
    //Success!
    $message = "The page was successfully updated.";
    } else {
    //Failed
    $message = "The page update failed.";
    $message .= "<br />" . mysql_error();

    }


    } else {
    if(count($errors) == 1){
    $message = "There was 1 error in the form.";

    } else {
    //Errors occurred
    $message = "There were " . count($errors) . " errors in the form.";
    }
    }
    //END FORM PROCESSING

    }//end: if(isset($_POST['submit']))
    ?>
    <?php find_selected_page (); ?>
    <div id="sidebar">

    <?php echo navigation($sel_subject, $sel_page) ?>

    </div>
    <div id="main">
    <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 urlencode($sel_page['id']); ?>"
    method="post">

    <p>Page name:
    <input type="text" name="menu_name" value="<?php echo $sel_page['menu_name']; ?>" id="menu_name" />
    </p>
    <p>Position:
    <select name="position">
    <?php
    $page_set = mysql_query("SELECT * FROM pages ORDER BY position ASC", $connection);
    $page_count = mysql_num_rows($page_set);

    for($count=1; $count <= $page_count+1; $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
    &nbsp;
    <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="50"><?php echo $sel_page['content']; ?> </textarea>
    </p>

    <input type="
    submit" name="submit" value="Edit Page" /> &nbsp; &nbsp;
    <a href="
    delete_page.php?page=<?php echo urlencode($sel_page['id']); ?>" onclick="return confirm('Are you sure you want to delete this page?');"> Delete Page </a>
    &nbsp; &nbsp;
    <a href="
    content.php?page=<?php echo $sel_page['id']; ?>">Cancel</a>

    </form>


    </div>


    I tried posting in Stackoverflow but didn't get a helpful response and I've sometimes had more luck here. The questions and responses that were posted on the other site are below .. maybe someone on here can help me get a little further in trying to figure this out...


    What is the exact error message ? and if you log/echo the actual query before its executed what does it look like ? and what datatype is the visible field in MySQL ? – ManseUK Jul 13 at 10:44
    What's the description of the visibility field in table? – Dainis Abols Jul 13 at 10:44
    when I hit submit it reloads the page and says: There was 1 error in the form. Please review the following fields: - visible – ristenk1 Jul 13 at 13:45
    the mysql databtype for visible is tinyint(1).. @ManseUK- I'm not sure how to log/echo the actual query before its exected – ristenk1 Jul 13 at 13:49
    Last edited by ristenk1; 07-16-2012 at 04:31 PM.

Posting Permissions

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