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 15 of 15
  1. #1
    New Coder
    Join Date
    May 2010
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Post Please help fix this page form code

    Please, can someone help me with code, any time i run it, it stop at the position point.
    the code is pasted below:

    PHP Code:

    <?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>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
        &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="80"><?php echo $sel_page['content']; ?></textarea>
    </p>
    Last edited by Inigoesdr; 07-01-2010 at 06:57 PM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Please use [PHP][/PHP] tags to wrap your PHP codes while posting here.

    it stop at the position point
    Hope you meant the text "Position:" near a drop down. If so, there might be some error in your query, which will not be visible to the browser output, since it breaks the drop down markup.

    You may either use the "view source" option of the browser OR move the query part to the top of the <select> tag, like
    PHP Code:
    <p>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;
    }
    echo 
    '<select name="position">';
    for (
    $count=1$count <=$page_count$count++) {
    echo 
    "<option value=\"{$count}\"";
    if (
    $sel_page['position'] == $count) { echo "selected";}
    echo 
    ">{$count}</option>";
    }
    echo 
    '</select>';
    ?>
    </p>
    Last edited by abduraooft; 07-01-2010 at 06:18 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    May 2010
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re:please help fix this page form code

    Thanks abduraooft, i tried checking the browser source code, it gave me this

    "Database query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use"

    i also tried moving the query part to the top of the <select> tag just has you said, it still not working.
    It says
    Position: Database query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY position ASC' at line 4

    i still need help

  • #4
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    Can you paste the SQL query?

  • #5
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Reread the first line in my above post. Thanks!
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #6
    New Coder
    Join Date
    May 2010
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I am sorry, i didnt take note

    PHP Code:
    <?php require_once("includes/dbconnection.php");?>
    <?php 
    require_once("includes/functions.php"); ?>
    <?php
        
    //make sure the subject id sent is an integer
        
        
        
    include_once("includes/form_functions.php");

        
    // START FORM PROCESSING
        // only execute the form processing if the form has been submitted
        
    if (isset($_POST['submit'])) {
            
    //initialize an array to hold our errors
            
    $errors = array();

        
    //perform validation on the form data
        
    $required_fields = array('menu_name''position''visible''content');
        
    $errors array_merge($errorscheck_required_fields($required_fields));

        
    $fields_with_lengths = array('menu_name' => 30);
        
    $errors array_merge($errorscheck_max_field_lengths($fields_with_lengths));

        
    // clean up the form data before putting it in 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 "CREATE pages SET
                    menu_name = '{$menu_name}',
                    position = {$position},
                    visible = {$visible},
                    content = '{$content}',
                WHERE id = {$id}"
    ;
            
    $result mysql_query($query);
            
    // test to see if the create occurred
            
    if (mysql_affected_rows() == 1) {
                
    // success!
            
    $message "The page was successfully created.";
            } else {
                
    $message "The page could not be created.";
                
    $message .= "<br />" mysql_error();
            }
        } else {
                if (
    count($errors) == 1) {
                    
    $message "There was 1 error in the form.";
                } else {
                    
    $message "There were"count($errors) . "errors in the form.";
                }
            }
            
    // END FORM PROCESSING        
        
    }
            
    ?>
    <?php find_selected_page
    (); ?>
    <?php 
    include("includes/header.php"); ?>
            <table id="structure">
                <tr>
                    <td id="navigation">
                        <?php echo navigation($sel_subject$sel_page,$public =false); ?>
                        <br />
                        <a href="/tonyson/new_page.php">+ Add a new subject</a>
                        
                  </td>
                    <td id="page">
                        <h2>Add New page</h2>
                        <?php if (!empty($message)) {echo "<p class=\"message\">" $message "</p>";}?>
                        <?php if (!empty($errors)) {display_errors($errors);}?>
                        <form action="/tonyson/new_page.php?subj=<?php echo $sel_subject['id']; ?> " method="post">
                        <?php $new_page true?>
                        <?php include "page_form.php" ?>
                        <input type="submit" name="submit" value="create Page" />
                    </form>
                    <br />
                    <a href="/tonyson/edit_page.php?subj=<?php echo $sel_subject['id']; ?>">Cancel</a><br />
                </td>
            </tr>
        </table>
    <?php include("includes/footer.php"); ?>

  • #7
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Can you paste the SQL query?
    $page_set = get_pages_for_subject($sel_page['subject_id']);
    $page_count =mysql_num_rows($page_set);
    You'd need to show the query generated inside the above function, I assume.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #8
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,542
    Thanks
    45
    Thanked 259 Times in 256 Posts
    PHP Code:
    $query "CREATE pages SET menu_name = '{$menu_name}', position = {$position}, visible = {$visible}, content = '{$content}', WHERE id = {$id}"
    Uh... what are you attempting to do here? I'm pretty sure CREATE is used to make tables, SET is used for stuff like updates (I've never seen it used in another setting). Are you attempting to update a row?
    Last edited by Keleth; 07-01-2010 at 06:46 PM.

  • #9
    New Coder
    Join Date
    May 2010
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    PHP Code:
    function get_pages_for_subject($subject_id,$public true){
            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

  • #10
    New Coder
    Join Date
    May 2010
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Keleth, i am trying to create a page with the query

  • #11
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,542
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Quote Originally Posted by aremzy View Post
    Keleth, i am trying to create a page with the query
    I will gladly admit I'm no pro at MySQL, but I have no idea what a MySQL page is... in fact, google has no idea what a MySQL page is... Are you trying to create a webpage dynamically populated via MySQL?

    I guess I'll hold from here to where someone more experienced can comment to "MySQL page".

  • #12
    New Coder
    Join Date
    May 2010
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Keleth, sorry for the way i put it, am trying to create a webpage dynamically populated via MySQL.

  • #13
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    Don't be so humble

    There's no such thing. Try running that query. It's not valid.

  • #14
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,542
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Meh Beagle, I leave my gaps in knowledge up to better minds Hell, becoming active on this forum has taught me not to underestimate my lack of knowledge

    But yah, CREATE isn't used in that way. If you want to add new data, its INSERT, to update existing data its UPDATE.

    Also, in regards to the error in post #3, I suspect $subject_id isn't being set properly. Have you tested it?

  • #15
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    What do you get when you echo that query in your function, like
    PHP Code:
    echo $query "SELECT * 
                    FROM pages 
                    WHERE subject_id={$subject_id}
                    ORDER BY position ASC"

    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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