Jump to content

refresh data after submit


RealDrift

Recommended Posts

Hi,

 

Basically I have a table displaying a simple word in a table. this word is pulled from a mysql table.

 

Below this I have a textbox where you can type in a new word and then click submit, which updates the sql table.

 

When the submit button is pressed and the old word is replaced by the new one in the table a message is echoed stating so.

 

When this is echoed I want the table to show the new word that just replaced the old one. Currently the message is echoed and the table shows the old word. I have to manualy refresh the page and then the new word is shown in the table.

 

Any help will be appreciated, I just can't seem to find an answer.

 

Thanks a lot

Link to comment
Share on other sites

There is many options.. two comes in mind now. First if and think you do fetch the word from db when thepage is loaded, you could just use header() and redirect the user after submit to the same page. In this way the new word would appear since the page is loaded automatically again. Or you can use AJAX to update the table in real time, which is a little more complex to do.

Link to comment
Share on other sites

What order do you have your functions in?

 

Make sure you have:

 

{

//do update database here

}

 

{

//retrieve 'word' from database here

}

 

That way you'll be putting the new word in, before getting that new word out.

 

This would work also, but redirect would be good because if the user refreshes the page the word is submitted again and new query will be done with the same values which means useless db queries. And in the worst case scenario if there is multiple users changing the word: mr A submits a word, then mr B submits new word, then A refreshes and mr B's new word is replaced with the mr A's old word. But don't know if this is the case.

Link to comment
Share on other sites

You will need AJAX to make it dynamic like you want without having to refresh the page. PHP won't be able to change the word without a refresh. even using a header or something like that is only a cosmetic change, as it still needs to refresh. Depending on the code, you may be able to use pretty simple javascript also, but I don't know how your script works, So i can't really say

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.