Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7878333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:37:45+00:00 2026-06-03T03:37:45+00:00

I’m trying to implement a form that utilizes jquery’s post feature to dynamically update

  • 0

I’m trying to implement a form that utilizes jquery’s post feature to dynamically update the database. What I’m realizing is that after the user clicks the “update” button, the success function is called back just fine with a “Update successful” message.

The issue I have for the stackoverflow world is why on subsequent clicks (w/o refreshing the page) I’m not getting this same success message. Also, ironically my database is being updated, so I know the AJAX call is going through.

I’ve posted my code below:

JS

var TEAM = { 
update: function() {

    var form_data = $('form').serialize();
    $.ajax({
        type: "POST",
        url: "../manager/edit_team.php",
        data: form_data,
        error: function() {
            $('#status').text('Update failed. Try again.').slideDown('slow');
        },
        success: function() {
            $('#status').text('Update successful!');
        },
        complete: function() { 
            setTimeout(function() {
                $('#status').slideUp('slow');
                }, 3000);
        },
        cache: false
    });
}
}

// jQuery Code for when page is loaded
$(document).ready(function()
{
 $("#update").on("click", function() {
     TEAM.update();
 });
 });

PHP (I welcome any other comments as well)

require '../includes/config.php';
include '../includes/header.html';

// autoloading of classes
function __autoload($class) {
    require_once('../classes/' . $class . '.php');
}

// Site access level -> Manager
$lvl = 'M'; 

// Assign user object from session variable
if (isset($_SESSION['userObj']))
{
    $manager = $_SESSION['userObj'];
}
else 
{
    session_unset();
    session_destroy();
    $url = BASE_URL . 'index.php';
    ob_end_clean();
    header("Location: $url");
    exit(); 
}

// Establish database connection
require_once MYSQL2;

// Assign Database Resource to object
$manager->setDB($db);

// Authorized Login Check
if (!$manager->valid($lvl))
{
    session_unset();
    session_destroy();
    $url = BASE_URL . 'index.php';
    ob_end_clean();
    header("Location: $url");
    exit(); 
}

// Check for a valid game sch ID, through GET or POST:
if ( (isset($_GET['z'])) && (is_numeric($_GET['z'])) )
{
    // Point A in Code Flow
    // Assign variable from myteams-m.php using GET method
    $id = $_GET['z'];
}
elseif ( (isset($_POST['z'])) && (is_numeric($_POST['z'])) )
{
    // Point C in Code Flow
    // Assign variable from edit_team.php FORM submission (hidden id field)
    $id = $_POST['z'];
}
else 
{
    // No valid ID, kill the script.
    echo '<p class="error">This page has been accessed in error.</p>';
    include '../includes/footer.html';
    exit();
}

$team = new ManagerTeam();
$team->setDB($db);
$team->setTeamID($id);
$team->pullTeamData();

$flag = 0;
echo $flag . "<br />";
// Confirmation that form has been submitted:   
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{   // Point D in Code Flow

    // Assume invalid values:
    $tname = FALSE;

    // Validate team name
    if ($_POST['tname'])
    {
        $tname = $_POST['tname'];

    }
    else 
    {
        echo '<p class="error"> Please enter a team name.</p>';
    }       

    // Validate about team information
    if ($_POST['abouttm'])
    {
        $abtm = trim($_POST['abouttm']);

    }
    else 
    {
        $abtm = '';
    }

    // Check if user entered information is valid before continuing to edit game
    if ($tname)
    {
        if($team->editTeam($tname, $abtm) == True)
        {
            echo '<p>Team was successfully updated</p>';
            $flag = 1;
        }
        else 
        {
            echo '<p>No changes were made</p>';
            $flag = 2;
        }
    }
    else
    {   // Errors in the user entered information
        echo '<p class="error">Please try again.</p>';
    }

}   // End of submit conditional.
echo $flag . "<br />";
// Point B in Code Flow
// Always show the form...

// Get team name attribute
$team->pullTeamData();
$teamname = $team->getTeamAttribute('tmname');
$about = $team->getTeamAttribute('about');

if ($teamname != '') // Valid user ID, show the form.   
{
    // Headliner
    echo '<h2>Edit Team</h2>';

    // Create the form:
    echo '
    <div id="EditTeam"></div>
    <div id="Team">
        <fieldset id="TeamDetails">
            <legend>Edit Team</legend>
            <form method="post" id="information">
            <p id="status"></p>
            <input type="hidden" name="z" value="' . $id . '" />                
            <p>
                <label for="tname">New Team Name:</label><br/>
                <input type="text" name="tname" id="tname" size="10" maxlength="45" value="' . $teamname . '" />
            </p>
            <p>
                <label for="abouttm">Team Information:</label><br/>
                <textarea id="abouttm" name="abouttm" cols="30" rows="2">"' . $about . '"</textarea><br />
                <small>Enter something cool about your team.</small>
            </p>
            <p>
                <input type="hidden" name="id" id="id">
                <input type="button" value="update" id="update" />
            </p>
        </form>
        </fieldset>
    </div>';                

}
else 
{   //Not a valid user ID, kill the script
    echo '<p class="error">This page has been accessed in error.</p>';
    include '../includes/footer.html';
    exit();
}   

// Close the connection:
$db->close();
unset($db);

include '../includes/footer.html';
?>

You’ll notice I also have a $flag defined to help with the debugging, but ironically it outputs 0 no matter the number of clicks to the “update” button. So there’s no indication that the database is being updated, yet when I check the tables it certainly is.

I appreciate any help or pointers. Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:37:47+00:00Added an answer on June 3, 2026 at 3:37 am

    #status message is not showing because you’ve hidden it by slideUp(), to show it again you need to slideDown() them.

        success: function() {
            $('#status').text('Update successful!');
    -ADD->  $('#status').slideDown('slow');
        },
        complete: function() { 
            setTimeout(function() {
                $('#status').slideUp('slow');
                }, 3000);
    

    Do it same way as you have done in error handler:
    success: function(){
    $('#status').text('Update successful!').slideDown('slow');
    ...

    It seems that you know it already and just forgot it…

    Other method that may be useful is stop() to make sure that previous animation is stopped when new one is starting., especially important when using long timeouts/animations.

    (useful = can prevent other problems with visibility and makes sure that messages does not start jumping in and out)

    (long = somewhere around 0,5-1,5 sec or more, if during this time can happen something else then it is long…)

    For example, this will clear fx queue, finish running animation immediately and slideUp():

    $('#status').stop(true, true).slideUp('slow');
    

    You also asked suggestions for other parts of code

    If you are using same code at least twice or if it is general method that could be reused make it reusable:

    function redirect_to( $page ) {
        session_unset();
        session_destroy();
        $url = BASE_URL . $page;
        ob_end_clean();
        header("Location: $url");
        exit(); 
    }
    
    if ($condition == true) {
        redirect_to( 'index.php' );`
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.