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
    Regular Coder
    Join Date
    May 2008
    Posts
    446
    Thanks
    23
    Thanked 5 Times in 5 Posts

    trouble updating my database

    I am trying to update my database and currently two of my fields I am trying to update are not setting, infact they get saved as blank.

    I have checked my html form, it is a spot on match for the name="". I am getting the form via Ajax call with the current data loaded in the fields. Ajax is not the problem bc 1 of the fields called via ajax is submitting properly to the database.

    Here is my code:
    PHP Code:
    function update_post()
    {
        
    // create new record
        
    if(isset($_POST['update'])) 
        {
            
    //echo 'update submit';
            
    $Database = new mysqli(##########);

            
    mysqli_report(MYSQLI_REPORT_ERROR);
            
                


            
    $post_title htmlentities($_POST['post_title'], ENT_QUOTES);
            
    $new_post_image htmlentities($_POST['new_post_image'], ENT_QUOTES);
            
    $current_post_image htmlentities($_POST['current_post_image'], ENT_QUOTES);
            
    $post_desc htmlentities($_POST['post_desc'], ENT_QUOTES);
            
    $post_id htmlentities($_POST['post_id'], ENT_QUOTES);
            
    $user_name htmlentities($_SESSION['user_name'], ENT_QUOTES);
            
    $now date("Y-m-d");
            
            
    $post_image $current_post_image;
            if(
    $new_post_image != '')
            {
                
    $post_image $new_post_image;
            }
            

            
    $post_title $Database->real_escape_string($user_title);
            
    $post_image $Database->real_escape_string($post_image);
            
    $post_desc $Database->real_escape_string($post_desc);
            
    $post_id $Database->real_escape_string($post_id);
            
    $user_name $Database->real_escape_string($user_name);
            
    $now $Database->real_escape_string($now);


            
            
            if (
    $Database->query("UPDATE posts SET post_title='".$post_title."', post_image='".$post_image."', 
            post_content='"
    .$post_desc."', post_user_update='".$user_name."', post_date_update='".$now."' 
            WHERE post_id='"
    .$post_id."'" ))
            

            {

                
            }
            else
            {
                echo 
    'Error: could not prepare SQL statement.<br />';
            }
            
            
    $Database->close();
            
    header("Location: posts.php");
        } 
    // end isset($_POST['submit'])
            
            
            
            
    // end update_post() 

    I made the update function not return to the same page and here is the error I got:

    ( ! ) Notice: Undefined index: current_post_image in C:\wamp\www\pentup_games\views\functions\query_post.php on line 21 Call Stack #TimeMemoryFunctionLocation 10.0039690080{main}( )..\posts.php:0 20.1937879224update_post( )..\posts.php:85 post_title: new post
    post_image:
    post_desc: Sucessful MySql query
    post_id: 1

    ( ! ) Notice: Undefined variable: user_title in C:\wamp\www\pentup_games\views\functions\query_post.php on line 38
    Call Stack
    # Time Memory Function Location
    1 0.0039 690080 {main}( ) ..\posts.php:0
    2 0.1937 879224 update_post( ) ..\posts.php:85
    Sucess: prepared SQL statement.
    post_title:
    post_image:
    post_desc: Sucessful MySql query
    post_id: 1
    " method="post" class="get_post_form">
    Last edited by surreal5335; 08-10-2011 at 11:25 AM.

  • #2
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    Looks like you just need to do some Basic Debugging 101 to find and fix the problem


  •  

    Posting Permissions

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