How to refresh a web page after submitting a form - php

m developing a website where you can search for any desired property by providing appropriate inputs. I am also providing a feature where you can take part in online auctioning of a property.
I have provided one input box where you can set your bid and submit for your bid.
on the top of that input box i am displaying the current highest bid which i am fetching from database. If the bid submitted by user is higher than the current highest bid then the line above the input box "Current highest bid is _" should automatically get updated.
But as I have written the logic for fetching and displaying highest bid from database on the top of my page n have implemented the rest of the logic for updating the database at the bottom of the page, m facing few errors,
somebody plz help me
Thanks in advance

If you want to refresh a webpage using php try this
header("Location:http://something/index.php");
Or if you want to get the highest bid from database periodically you will have to use AJAX.

You can refresh your page with the help of JavaScript
location.reload();

there are two ways
1) just submit form to server without any ajax content.(it will be updated and loaded as default behavior)
2)use ajax(jQuery.load or jQuery.ajax will be easiest).
- submit form in the click method of jquery,
- print bid status as the response.
- Catch this response process it and update your data on page.
- to prevent page refresh, use event.preventDefault or return false at end of function

Related

Post to a different page but stay on the current page

I have a requirement, 2 php pages, one for entry purposes and another for display purposes.
Page 1- badgeentry.php allows an admin to enter badges numbers 123 and clicks submit.
Page 2 - badgedisplay.php allows all other users to view what the current badge number is. In this case 123. This page is using the "Refresh" meta html tag.
As far as the development, I have badgeentry and badgedisplay coded for. However, I want admins to stay on badgeentry after submit is clicked and still post data to badgedisplay. How can I do that?
Also, how do i maintain the badge number until the number is updated by admin. Currently, I lose the post value on badgedisplay page.
PS: I cannot use databases, maybe Javascript if I really have to
Thanks in advance.
With JavaScript: Use AJAX to post asynchronously in the background.
Without JavaScript: Post to a hidden iframe (with <form target="name-of-iframe">)

display data from database, edit it, but when click on previous page, the data gone.

i got 4 pages which are company details, job requirements, job responsibilities and design. so im gonna update the data from these pages. so i retrieve the data from database to be display into form for these 4 pages. after i edit the values on first page, then i go to next page for next update. but when i go back to previous page, the data wont keep the edited value but display the old data that i retrieved from database. so how to prevent this to happen ? same goes if i refresh the pages. i know i can use the session to store edited value but still i think that form will display the old data. help me give the idea how to do this pls ! thanks
You need to follow below steps
Go to next page by submit & action attribute
In next page hold all the post value into hidden fields
Use a back button to go back.
when go button will be pressed submit the form which is holding the hidden fields
Now you are in first page and simply use $_REQUEST or $_POST to get the previous value.
Hope you under stand.
N.B: If you use browser back button browser will ask you to confirm to resubmit the form. If you confirm then no problem but if you didn't confirm then you lost your values.

Update select contents without reloading form

I have quite a long form which has many HTML form selects pulling data from MySQL tables - quite often a client will be mid way through filling in the form when they realise that the value they want for department, for example, has not yet been entered into the system so is not in the list.
I have added a link to a simplified popup for adding departments but after it is added it does not appear in the select list as the contents of that select are based on what was available on the load of the page when the initial query ran - how can I get the select to update without having to submit and then edit, without the page refreshing/reloading and without the client losing the data they have currently added?
Thanks
Did read what you are asking, since its too long) But did you try javascript? changing form values after paged loaded is possible only with javascript.
When submit form on that popup, save it with ajax in database, and as response get inserted data... Then on ajax success add new option in select ( with returned data )

How can i submit data to a php page without going to that page right away?

I need to take form data from user input- i.e. radio buttons and use that to apply search filters to a database search.
However there are specific parameters which are giving me difficulty.
Specifically: The search filter options pane is a static fixture on the main page of the site. The query to be modified by the search filters is a separate php page which is called by an ajax function to display search results in the middle of the page without page refresh.
Is it even possible to submit variable values to another php page without going to that page and processing the php immediately? Or will the variables not be stored like that?
The code is too long but I'll give basic pseudocode:
Form action="Query Page to receive user input.php"
Some radio buttons:
20
15
10
Submit button--> Submits the radio button value to QueryPage.php but does not redirect
User clicks a category link (i.e. fitness) that calls the ajax function which displays the output of QueryPage.php. At this point QueryPage.php should perform the search with the specific user input filters that were selected earlier.
Is this possible?
Let me see if I understand correctly:
You're basically saying that your radio buttons will modify the search results, based on the what user selected?
If that's the case, I can think of 2 options:
1- When you make the ajax request for the search, first, grab the user input and send it to the QueryPage.php file with the search query. Do you have access to that function?
2- Post the user input using ajax (are you using jQuery or some other library for this?) to a UserInput.php file, where you'll store that data on the session, and then from QueryPage.php you just access the session and grab the values sent previously.
Does that answer your question? Sorry if it doens't, it's a bit hard to understand the problem.
You can use JQUERY and its events method. For example change,click,hover. In your case you want to use radio buttons, so you might wanna use the click event for that.
$("#radio").click(function () {
// SEND HTTP REQUEST
});
http://www.mkyong.com/jquery/how-to-select-a-radio-button-with-jquery/
Yes. You could just use .ajax(), or .post() or cURL. This will post your data to the specified page without redirecting.
Example using .post()
$.post("test.php", { name: "John", time: "2pm", fieldname: "your value" } );

Refreshing the page after adding data? PHP

Is there any way to refresh the data after I click the submit button? Currently as I click the submit button on my PHP page, there are changes to the database. But, I will have to refresh the page itself to see the updated result, which I think it is quite incompetent.
To add on, what I am doing is on a table form. So example,
1) 14 Dogs.
So after i edit 14 dogs to 13 dogs and submit, the changes are successful as seen in the database, but the value won't change unless I refresh the page. Thank you all.
Additional Info:
I'm using XAMPP, Microsoft Access.
in your script, instead of
code that outputs data from database
code that updates database
do
code that updates database
code that outputs data from database
I just changed the order. Hopefully its obvious why.
im assuming youre using a regular form, no ajax or frames.

Categories