leachus2002 Posted September 7, 2010 Share Posted September 7, 2010 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 https://forums.phpfreaks.com/topic/212767-posting-form-to-the-same-page/ Share on other sites More sharing options...
vijdev Posted September 7, 2010 Share Posted September 7, 2010 you are not clear!, or sorry atleast i dont understand what u need! Link to comment https://forums.phpfreaks.com/topic/212767-posting-form-to-the-same-page/#findComment-1108269 Share on other sites More sharing options...
leachus2002 Posted September 7, 2010 Author Share Posted September 7, 2010 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 https://forums.phpfreaks.com/topic/212767-posting-form-to-the-same-page/#findComment-1108274 Share on other sites More sharing options...
rwwd Posted September 7, 2010 Share Posted September 7, 2010 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 https://forums.phpfreaks.com/topic/212767-posting-form-to-the-same-page/#findComment-1108277 Share on other sites More sharing options...
vijdev Posted September 7, 2010 Share Posted September 7, 2010 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 https://forums.phpfreaks.com/topic/212767-posting-form-to-the-same-page/#findComment-1108280 Share on other sites More sharing options...
vijdev Posted September 7, 2010 Share Posted September 7, 2010 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 https://forums.phpfreaks.com/topic/212767-posting-form-to-the-same-page/#findComment-1108281 Share on other sites More sharing options...
leachus2002 Posted September 7, 2010 Author Share Posted September 7, 2010 Hi Vijdev, Thanks for that I will give it a go - what would happen if someone refreshes the page? Thanks Matt Link to comment https://forums.phpfreaks.com/topic/212767-posting-form-to-the-same-page/#findComment-1108284 Share on other sites More sharing options...
vijdev Posted September 7, 2010 Share Posted September 7, 2010 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 https://forums.phpfreaks.com/topic/212767-posting-form-to-the-same-page/#findComment-1108285 Share on other sites More sharing options...
leachus2002 Posted September 7, 2010 Author Share Posted September 7, 2010 Oh I forgot to ask - where to I send the form to? Is it back to the page, or php_Self? Thanks Matt Link to comment https://forums.phpfreaks.com/topic/212767-posting-form-to-the-same-page/#findComment-1108286 Share on other sites More sharing options...
rwwd Posted September 7, 2010 Share Posted September 7, 2010 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 https://forums.phpfreaks.com/topic/212767-posting-form-to-the-same-page/#findComment-1108289 Share on other sites More sharing options...
leachus2002 Posted September 7, 2010 Author Share Posted September 7, 2010 Hi Vijdev, Sorry mate, but I am getting loads of errors using that code - seams to be having issues with the second line - also I cannot see where the brackets close after the ( ISSET Any ideas? Cheers Matt Link to comment https://forums.phpfreaks.com/topic/212767-posting-form-to-the-same-page/#findComment-1108296 Share on other sites More sharing options...
vijdev Posted September 7, 2010 Share Posted September 7, 2010 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 https://forums.phpfreaks.com/topic/212767-posting-form-to-the-same-page/#findComment-1108300 Share on other sites More sharing options...
vijdev Posted September 7, 2010 Share Posted September 7, 2010 Oh I forgot to ask - where to I send the form to? Is it back to the page, or php_Self? Thanks Matt rwwd is right, use the same filename.php to post it. yes Link to comment https://forums.phpfreaks.com/topic/212767-posting-form-to-the-same-page/#findComment-1108302 Share on other sites More sharing options...
leachus2002 Posted September 7, 2010 Author Share Posted September 7, 2010 Doh, got it now! Formatting was wrong Link to comment https://forums.phpfreaks.com/topic/212767-posting-form-to-the-same-page/#findComment-1108303 Share on other sites More sharing options...
rwwd Posted September 7, 2010 Share Posted September 7, 2010 Lol Success, if only it were beer o'clock now! Cheers, Rw Link to comment https://forums.phpfreaks.com/topic/212767-posting-form-to-the-same-page/#findComment-1108304 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.