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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    New Coder
    Join Date
    Oct 2012
    Location
    Philippines
    Posts
    14
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Post im getting an error when im submitting 'content' to my database.. need help here..

    Im a beginner in world of php, and i don't know how to solve this problem,can someone help me.. Please.. thanks in advance... here's my code in new_page.php,
    I forgot to say the correct specification of the problem codes new_page.php I dare to do. because I'd love to add a new page in the browser does not work with the error content part and written says:
    The page could not be updated.
    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'' at line 6 ..
    That is why I need the help of a good man who could solve my problem. thanks in Advance.. :

    <?php require_once("connection.php"); ?>
    <?php require_once("function.php"); ?>
    <?php
    // make sure the subject id sent is an integer
    if (intval($_GET['subj']) == 0) {
    redirect_to("content.php");
    }

    include_once("form_function.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 validations on the form data
    $required_fields = array('menu_name', 'position', 'visible', 'content');
    $errors = array_merge($errors, check_required_fields($required_fields));

    $field_with_lengths = array('menu_name' => 30);
    $errors = array_merge($errors, check_max_field_lengths($fields_with_lengths));

    // clean up form data before putting it in the database
    $id = mysql_esc($_GET['page']);
    $menu_name = trim(mysql_esc($_POST['menu_name']));
    $position = mysql_esc($_POST['position']);
    $visible = mysql_esc($_POST['visible']);
    $content = mysql_esc($_POST['content']);

    // Database submission only proceeds if there were NO errors.
    if (empty($errors)) {
    $query = "UPDATE page SET
    menu_name = '{$menu_name}',
    position = {$position},
    visible = {$visible},
    content = '{$content}'
    WHERE id = {$id}";
    $result = mysql_query($query);
    // test to see if the update occured
    if (mysql_affected_rows() == 1) {
    // Success!
    $message = "The page was successfully updated.";
    } else {
    // Failed
    $message = "The page could not be updated.";
    $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("header.php"); ?>
    <table id="structure">
    <tr>
    <td id="navigation">
    <?php echo navigation($sel_subject, $sel_page, $public = false); ?>
    <br />
    <a href="new_subject.php">+ Add a new subject</a>
    </td>
    <td id="page">
    <h2>Adding New Page</h2>
    <?php if (!empty($message)) {
    echo "<p class=\"message\">" . $message . "</p>";
    } ?>
    <?php if (!empty($errors)) { display_errors($errors); } ?>

    <form action="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="edit_subject.php?subj=<?php echo $sel_subject['id']; ?>">Cancel</a><br />
    </td>
    </tr>
    </table>
    <?php include("footer.php"); ?>

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    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'' at line 6 ..
    Change
    PHP Code:
    $query "UPDATE page SET
    menu_name = '{$menu_name}',
    position = {$position},
    visible = {$visible},
    content = '{$content}'
    WHERE id = {$id}"

    to
    PHP Code:
    echo $query "UPDATE page SET
    menu_name = '{$menu_name}',
    position = {$position},
    visible = {$visible},
    content = '{$content}'
    WHERE id = {$id}"

    and post the output here.

    PS: Please edit your post and add [PHP][/PHP] tags around your code, to make it readable. Thanks.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    crisean (10-22-2012)

  • #3
    New Coder
    Join Date
    Oct 2012
    Location
    Philippines
    Posts
    14
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Question thank you for helping me... but,i got bad news...

    The problem is it still not working, my difficult part is i don't know how to spot the errors,here's the one I code edit_page.php, because the link still not out (forgive me if you would torture you, because I just really want to learn php, many thanks if you can help me.):
    <?php require_once("connection.php"); ?>
    <?php require_once("function.php"); ?>
    <?php
    // make sure the subject id sent is an integer
    if (intval($_GET['page']) == 0) {
    redirect_to("content.php");
    }

    include_once("form_function.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 validations on the form data
    $required_fields = array('menu_name', 'position', 'visible', 'content');
    $errors = array_merge($errors, check_required_fields($required_fields));

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

    // clean up the form data before putting it in the database
    $id = mysql_esc($_GET['page']);
    $menu_name = trim(mysql_esc($_POST['menu_name']));
    $position = mysql_esc($_POST['position']);
    $visible = mysql_esc($_POST['visible']);
    $content = mysql_esc($_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);
    // test to see if the update occured
    if (mysql_affected_rows() == 1) {
    // Success!
    $message = "The page was successfully updated.";
    } else {
    $message = "The page could not be updated.";
    $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("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="editing_page.php?page=<?php echo $sel_page['id']; ?>"
    method="post">
    <?php include "page_form.php" ?>
    <input type="submit" name="submit" value="Update Page" />&nbsp;&nbsp;
    <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>
    <?php include("footer.php"); ?>

  • #4
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    333
    Thanks
    2
    Thanked 47 Times in 46 Posts
    Crisean,
    This:
    Quote Originally Posted by abduraooft View Post
    Change
    PHP Code:
    $query "UPDATE page SET
    menu_name = '{$menu_name}',
    position = {$position},
    visible = {$visible},
    content = '{$content}'
    WHERE id = {$id}"

    to
    PHP Code:
    echo $query "UPDATE page SET
    menu_name = '{$menu_name}',
    position = {$position},
    visible = {$visible},
    content = '{$content}'
    WHERE id = {$id}"

    and post the output here.

    PS: Please edit your post and add [PHP][/PHP] tags around your code, to make it readable. Thanks.
    Was not supposed to solve the problem but to shed light on the specific nature of it by echoing it out. So do as said above and post the output of the echo here.

    Offtopic: Don't use $_POST['submit'] to check whether a form has been submitted. Here's why.

    And do use [PHP] tags to wrap your code mate.
    Last edited by Redcoder; 10-22-2012 at 11:31 AM.

  • Users who have thanked Redcoder for this post:

    crisean (10-23-2012)

  • #5
    New Coder
    Join Date
    Oct 2012
    Location
    Philippines
    Posts
    14
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Question oohhh.. yeah i forgotten to edit my post.

    ahm, should it be LIKE this?
    (I hope you forgive me because I do not immediately understand, I still make mistakes (but I really want to learn), sometimes I just do not understand ..) :



    <?php require_once("connection.php"); ?>
    <?php require_once("function.php"); ?>
    <?php
    // make sure the subject id sent is an integer
    if (intval($_GET['subj']) == 0) {
    redirect_to("content.php");
    }

    include_once("form_function.php");

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

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

    $field_with_lengths = array('menu_name' => 30);
    $errors = array_merge($errors, check_max_field_lengths($fields_with_lengths));

    // clean up form data before putting it in the database
    $id = mysql_esc([PHP]);
    $menu_name = trim(mysql_esc(PHP));
    $position = mysql_esc([PHP]);
    $visible = mysql_esc([PHP]);
    $content = mysql_esc([PHP]);

  • #6
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    333
    Thanks
    2
    Thanked 47 Times in 46 Posts
    Your still posting the same way as before. Use [PHP] to highlight the code and syntax.

    You have not posted the error, haven't followed what Abduraooft told you. Add 'echo' where he told you to or mysql_error() to your code.

    Read this thread on VBulletin [PHP] tags - http://www.codingforums.com/showthread.php?t=68462

  • Users who have thanked Redcoder for this post:

    crisean (10-23-2012)

  • #7
    New Coder
    Join Date
    Oct 2012
    Location
    Philippines
    Posts
    14
    Thanks
    12
    Thanked 0 Times in 0 Posts

    thanks for the little help, i already did what abduraooft told me,even your advices..

    But, it still doesn't work, i guess there's a little bit problem on my syntax either on the edit_page.php(code) or new_page.php(code) or maybe in my page_form.php(a new code where my formed place):

    // thanks for helping me again...
    // this is my page_form.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>

  • #8
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    333
    Thanks
    2
    Thanked 47 Times in 46 Posts
    If this is still you errror:
    Code:
    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'' at line 6 ..
    The problem is not in page_form.php. It's in new_page.php . If you want to get to the bottom of it, debug this :

    PHP Code:

    $query 
    "UPDATE page SET
    menu_name = '{$menu_name}',
    position = {$position},
    visible = {$visible},
    content = '{$content}'
    WHERE id = {$id}"
    ;
    echo 
    $query//Add this and then post what is echoed back here so that we can help you. We can't help you if we don't know what the query looks like
    $result mysql_query($query) or die(mysql_error()); //See the mysql_error I added here 
    Read the comments in the code and then post back so that we can help you

  • Users who have thanked Redcoder for this post:

    crisean (10-23-2012)

  • #9
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post
    Hi good day, i think you don't need to use braces?? It should be parentheses. Also, your code is to crowded, you can use indention's so the codes will be much clearer.

    You can start from the basics before proceeding with difficult topics. You need a basic background of the topic. Well, you can find helpful tips in w3schools. It is a free web tutorial for any programming language.

    Good luck and hope you find a solution to your problem. =)

  • Users who have thanked JohnRomanPHP for this post:

    crisean (10-23-2012)

  • #10
    New Coder
    Join Date
    Oct 2012
    Location
    Philippines
    Posts
    14
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Question i already did it thanks, but i think it's more complicated...

    i already had the thoughts in my mind that the problem is the new_page.php code is the problem, but because i am a beginner i just blame edit_page.php code and page_form.php code... Sorry bout it..



    ohhh by the way i add it already in my code the php code that you gave and then i started to add a new page and it echoed this error message:

    UPDATE page SET menu_name = 'Test Page', position = 3, visible = 1, content = 'This is a test.' WHERE id = 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 '' at line 6

    is there a possible ways we can fix it? sometimes i always reviewed my syntax for expecting maybe that there is a lacking on my codes... sorry for the interuptions again... thanks in advance SIR REDCODER.!

  • #11
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    333
    Thanks
    2
    Thanked 47 Times in 46 Posts
    Do you see the below, id= ???? NOthing so that means that the problem is the $id variable which is empty.
    Quote Originally Posted by crisean View Post
    PHP Code:
    UPDATE page SET menu_name 'Test Page'position 3visible 1content 'This is a test.' WHERE id 
    Code:
    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 '' at line 6
    So the problem originates from:

    Code:
    $id = mysql_esc($_GET['page']);
    You should first check whether $_GET['page'] is empty or not. So add something like :

    PHP Code:
    if(!empty($_GET['page'])){
    $id mysql_esc($_GET['page']);
    }
    else{
    //Jump everything and prompt user to enter the page input field


  • Users who have thanked Redcoder for this post:

    crisean (10-23-2012)

  • #12
    New Coder
    Join Date
    Oct 2012
    Location
    Philippines
    Posts
    14
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Unhappy im sorry im ashamed onto you right now...

    sorry again if im cuddled you again for helping me...

    cause i already put it in, but still it gave me back the error message that i replied to you which the $id variable is empty...


    im sure that your confused also on my problem... im really really sorry SIR!

  • #13
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    333
    Thanks
    2
    Thanked 47 Times in 46 Posts
    Quote Originally Posted by crisean View Post
    sorry again if im cuddled you again for helping me...

    cause i already put it in, but still it gave me back the error message that i replied to you which the $id variable is empty...


    im sure that your confused also on my problem... im really really sorry SIR!
    Post the new code which you have after applying the above solutions.

  • Users who have thanked Redcoder for this post:

    crisean (10-24-2012)

  • #14
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    How does the url in the address bar of your browser look like, when you get all these errors?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    crisean (10-24-2012)

  • #15
    New Coder
    Join Date
    Oct 2012
    Location
    Philippines
    Posts
    14
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Question sorry for the big problem that i throwed to you GUYS.. i apologize!

    Here is the new code for the new_page.php code that i apply after i read your certain solutions sir Redcoder:



    <?php require_once("connection.php"); ?>
    <?php require_once("function.php"); ?>
    <?php
    // make sure the subject id sent is an integer
    if (intval($_GET['subj']) == 0) {
    redirect_to("content.php");
    }

    include_once("form_function.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 validations on the form data
    $required_fields = array('menu_name','position','visible','content');
    $errors = array_merge($errors, check_required_fields($required_fields));

    $field_with_lengths = array('menu_name' => 30);
    $errors = array_merge($errors, check_max_field_lengths($fields_with_lengths));

    // clean up form data before putting it in the database
    if(!empty($_GET['page']))
    $id = mysql_esc($_GET['page']);
    $menu_name = trim(mysql_esc($_POST['menu_name']));
    $position = mysql_esc($_POST['position']);
    $visible = mysql_esc($_POST['visible']);
    $content = mysql_esc($_POST['content']);

    // Database submission only proceeds if there were NO errors.
    if (empty($errors)) {
    $query = "UPDATE page SET
    menu_name = '{$menu_name}',
    position = {$position},
    visible = {$visible},
    content = '{$content}'
    WHERE id = {$id}";
    echo $query; // Add this and then post what is echoed back here so that we can help you. We can't help you if we don't know what the query looks like
    $result = mysql_query($query) or die(mysql_error()); // See the mysql_error I added here
    $result = mysql_query($query);

    // test to see if the update occured
    if (mysql_affected_rows() == 1) {
    // Success!
    $message = "The page was successfully updated.";
    } else {
    // Failed
    $message = "The page could not be updated.";
    $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("header.php"); ?>
    <table id="structure">
    <tr>
    <td id="navigation">
    <?php echo navigation($sel_subject, $sel_page, $public = false); ?>
    <br />
    <a href="new_subject.php">+ Add a new subject</a>
    </td>
    <td id="page">
    <h2>Adding New Page</h2>
    <?php if (!empty($message)) {
    echo "<p class=\"message\">" . $message . "</p>";
    } ?>
    <?php if (!empty($errors)) { display_errors($errors); } ?>

    <form action="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="edit_subject.php?subj=<?php echo $sel_subject['id']; ?>">Cancel</a><br />
    </td>
    </tr>
    </table>
    <?php include("footer.php"); ?>





    and here's the address "http://localhost/widget_corp/new_page.php?subj=1"
    and at the browser's page i saw a big error message: "UPDATE page SET menu_name = 'Test Page', position = 3, visible = 1, content = 'This is a test.' WHERE id = 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 '' at line 6"
    (no background color it's totally all white background...)


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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