Jump to content

Posting form to the same page


leachus2002

Recommended Posts

Hi There,

 

I have a series of submit buttons that I would like to update records in a table when they are pressed. For example, when clicked, I would like them to run the following statement:

 

update mytable set completed = 1 where colname = $variable

 

I would then like it to refresh the page.

 

Is there a way of doing this?

 

Thanks

Matt

Link to comment
Share on other sites

Hi Videv,

 

Basically, when I click on the submit button on my page I need it to refresh, but at the same time, update a table.

 

The background is that I have a daily task planner that when a person has completed a specific task, they click the "complete" button, which then removes the task from the page. In reality, the "complete" button updates the DB to say that the task has been completed and then it is removed from view.

 

Hope that helps?

 

Thanks

Matt

Link to comment
Share on other sites

Sounds like your after Jquery/Ajax stuff to me, I don't know much of that, but colleagues of mine swear by it because you can virtually do away with <form> tags, primarily because of it being asynchronous, effectively refreshing the div when doing a submit & not refreshing the page.

 

Cheers,

Rw

Link to comment
Share on other sites

ok, now i understand.

sure, so thats not a problem..

try on these lines:

 

if (isset($_POST['submit'] && $_POST['submit']=='Update')
{
       if (POST inputs validated)
           {
               update table;
               set the table variables to the new variable value;
           }
}
query DB and assign the variables its values..(this will be new values if above section updates the table, else existing DB values; either way this will feed your table display.)

display table with variable values;

Link to comment
Share on other sites

Sounds like your after Jquery/Ajax stuff to me, I don't know much of that, but colleagues of mine swear by it because you can virtually do away with <form> tags, primarily because of it being asynchronous, effectively refreshing the div when doing a submit & not refreshing the page.

 

Cheers,

Rw

 

am in the same boat..no ajax and no JS! :(

Link to comment
Share on other sites

Hi Vijdev,

 

Thanks for that I will give it a go - what would happen if someone refreshes the page?

 

Thanks

Matt

 

if you just refresh by browser button, after taking user confirmation for "resend data"..or some fancy mssg depending on the browser.

and it must dislpay existing DB values and not update anything...

Link to comment
Share on other sites

Oh I forgot to ask - where to I send the form to? Is it back to the page, or php_Self?

 

I wouldn't use $_SERVER['PHP_SELF']; as there are security issues with it; just put the file name in of the file you are using in the action attribute or leave it blank, as it's default action is to post to itself anyway, though many people say that's not a good idea, you always need a value defined in the action attribute to satisfy validation criteria (so I am told anyway)

 

Cheers,

Rw

Link to comment
Share on other sites

sorry, i missed a brkt...see it below in bold and underline..

anyway, what ive given below is a general overview, you really need to think of assigning default values to these variables, when would it finalize the value from the form, when would it take from the DB, and finally display in the table...there is quite a lot of preiphals to do..keep working, and when you have a decent amount of lines worked out, post it here and we can work thru..mk sure you think of the sequence in which the application would be execute, think of the boundary conditions...etc.

 

if (isset($_POST['submit'][b][u])[/u][/b] && $_POST['submit']=='Update')
{
       if (POST inputs validated)
           {
               update table;
               set the table variables to the new variable value;
           }
}
query DB and assign the variables its values..(this will be new values if above section updates the table, else existing DB values; either way this will feed your table display.)

display table with variable values;

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.