PHP sending data to the redirected page - php

I am building a small website for viewing and amending data entries in a database.
I have a form where a user can select the table they want to view in a drop down select.
On submit I call a php script which handles pulling the data and then redirects to the .html site on which I want to display the results.
I know that my script works in that if I do not use the header redirect the correct results are printed.
I am wondering how I can access the data from the website I'm redirecting to so that I could display them.
I would welcome any alternative suggestions.

The .html implies static data, are the tables always static or are you loading from a data source (mysql, etc)? If you're just trying to load a static HTML page from a drop down, then maybe you should just use javascript?
http://webdesign.about.com/od/javascript/f/blfaqddredirect.htm
Unless I am mistaken on what you are attempting to do.

Related

how to get the the data instantly after inserting in database in php?

I am creating a website audit tool now in this someone will insert details of their website and answer some questions and i am inserting that in the database. Now I want to show results in new page according to the choices user makes now how can I get the details of that inserted data instantly any way to get that through PHP?
Yes, the same way you would normally get data. When loading the new page, have your controller load the data and then include it.
If this is asynchronous or doesn't include a page refresh, then you could handle this more quickly with JavaScript.

View live updates from MySQL database?

I want to create a page where people can insert some text, hit enter, and the text be stored in a MySQL database. I can do this, but I want to be able to load a page, enter a password, and see a list of all the info in said database, then whenever something is added to the database, it's added to the list on the page, without me needing to refresh the page or setup some javascript code to refresh the page every five seconds.
I believe Satya has it correct in suggesting that you use Ajax in order to refresh the data without refreshing the page. You can have it request updated information from a php script which queries your database for the data you wish to display, and then sets the elements on your page accordingly.
this is probably the best way for you to implement ajax calls using javascript
http://api.jquery.com/jQuery.ajax/
Or you an simly do it with the help of setInterval() function. You can call an html code in a div using
$('#id').html("<htmlcode></htmlcode>");
Example : http://jsfiddle.net/ipsjolly/995PJ/6/

Page refresh without reloading a page and calling external files in php ajax

I have a profile page where im showing the friends of that user from db, I'm using auto scroller that works fine if I place that data directly in main file not an external file, Also I have a drop down that on selection will sort the friends records accordingly, but as I have moved the code to main file, I need to make ajax call to same file not an external, to repopulate data with required sorting.
Please let me know how can i do this on same file with ajax. On selection of drop down value.
Have you considered using Jquery?
Its surprisingly easy. You just need to do $('#contentdiv').load('contentyouwant') where you bind the event for the ddl.
If you must use the same file, place the code that will be ran by ajax, in a function. then at the beginning of the page, evaluate if this was the ajax call or the whole file.
Hope it helps.

How to share a form between 2 websites

I have a form which I'd like to share between 2 different websites. The form is submitted and the data is entered into the database.
Right now each website has its own copy of the script and its own database, so when I want to make updates to the form, I have to make those changes twice. Is there a way to share the form between the 2 websites, yet make it look like its being served by each website like normal. I'm also wondering if it's possible to make all the data go to one database.
The basic options would be...
You could use an html iframe to show the same form on multiple websites.
You could copy the form code between sites
If both websites are on the same server, you may be able to get a php include to include the form (this is possible in some cases even if they are not)
You can certainlly get the database to share information, just ensure the user you use to connect to it is allowed to connect from anywhere - not just localhost and you can connect to the database remotely.
You could include the form inside the other website as an iframe.
There is a short tutorial here on howto do that.
In case the form is displayed inside a whole complex page i recommend placing the form inside its own page and iclude it in both websites using an iframe.
depends what you are looking for, if you use the same process script behind it, do what Mouhannad said, and add a field "return_url" so you come back on the right page.
if it is that you want to send the fields to 2 different locations, create a proxy script and post it by a curl to both locations.
you can simply make both forms (in both websites) point to the same php page (in one of the websites)
<form action="http://www.example.com/action.php" ... >
Then check for the url reference to send the user back to the same page
The user won't feel any difference and you will have the database connection in one place
good luck!
Edit:
I thought your main concerns were the backend code since you mentioned the database. You could use iframes as suggested by the others but I always try to avoid them as much as I can. You can find lots of material online about why you should avoid them.
The other solution is use cURL to get the form's html code from the external page and keep using my above suggestion to change the action url path. This way you have the same code both for the backend and frontend. The downside is that you are making an additional request to get the form's html code which adds to the performance of your website - caching should improve that!
You can use CURL to simulate form submitting on another host, just send POST request with $_POST data.

Search MySQL Database

Hey, I have put together an iPhone web app and i'm currently reading and displaying data from a MySQL database. I have added a search bar to this page and was wondering what the best way would be to search the content on the page.
My page
The best way to do this would be via AJAX. When you click "Search", make an AJAX call with the supplied search string to a PHP page. The PHP page will then take that string and make a MySQL call that will return the data set. The PHP can then return the dataset back to your HTML page.

Categories