What I made so far:
A button that opens a new .html page (in a new browser tab), with some inputs to store data in a MySQL database (by pressing the submit button using <form> and a PHP script).
I want to display the content of my MySQL database on my index.html file (e.g. in a <p> or a table) by pressing (another) button.
Displaying the content by using a PHP script as when I save something in the database works (like descripted here https://www.w3schools.com/php/php_mysql_select.asp), but I don't want to display the results in a new site, I want to display it in my "index.html".
Is there a proper way for doing this or do I have to make the whole index.html file a PHP file?
If you don't want to change the .html to .php use ajax to fetch data from db when you click on your button ,then diplay it on your table
Not necessarily, what you should keep in mind is that a call to an html or php page is a request made to a web server which delivers the information back to the client, under this paradigm an index.html or index.php It is only executed once, if your SQL query is executed without modifications the first time the page is loaded, it would be enough to make the page design contemplate the space to show the result of said query, if what you want is that the client modify the SQL to show the new result of said query in your page index.html or index.php you should reload the page with the new query or else use ajax to only reload a part of the page and make ajax perform the loading the data with the new query.
In any case index.html can contain php or php code it can also contain html
index.php
echo "<html>";
echo "</html>";
index.html
<html>
<?php
echo "some php code";
?>
</html>
Related
I want to create a new webpage using php. Then after I create the page I would like to open the page in a browser. I have the create part (create file) down and the delete file, but how do I (can I?) open the webpage from my php created page that has confirmation message?
To clarify, I have created an html page that asks the user to enter information to create a web page. I ask the name of the webpage, extension type, and a text box for content. I then give them 3 buttons - Create page, view page, delete page. If the user selects Create, I then run a php page that creates the file for the webpage and displays a message that the web page was created.
So, my question is how do I either return to the html page to allow the user to select view webpage(which does not require php) or to allow the user to select to view the webpage from the "Confirmation" page which is php?
Thanks,
Jason
You can alter the header file to do this, and some people may suggest this, but I've found that this causes issues without knowing more code that's been written before or afterwards.
I recommend that you use JavaScript to change the location of the page and simply place an "onclick" or "onsubmit" call to the below function on the button that creates the page.
<script>
function createAndRedirect(){
var x = document.getElementById("#idOfInputWhereWebPageIsSet");
var y = x.value;
// You can add an alter confirmation message here.
// alert("Web Page Created!"); Remove the comment slashes for a basic confirmation alert.
location.replace(y);
}
</script>
My html has a table cell which shows the content of a text file (read in by javascript) containing the names of former visitors. This works perfectly.
There is also a form for inserting the visitor's name.
On submit an external php is started which adds the new name to the text file. This is working perfectly too.
At the moment the form begins with this:
<form method="post" action="write2txt.php" target="_blank">
But what I want is: After submit the html simply should refresh to show the updated visitor list.
Don't use target="_blank" in your form, since that displays the results in a new window. Change write2txt.php so that after it writes to the file, it sends back a redirect to the original page's URL, instead of producing its own output.
<?php
// code to update file
header("Location: form.php");
exit();
This will make the browser reload the original page, which will get the updated contents of the file.
If you don't want to use AJAX, this is the general idea of how you have to do it.
(read in by javascript) & no ajax, means what?
Hints
javscript files are catched, keep that in mind
why not adding the date with php in the first place
if the table and the adding is in one file, adding should before outputing the table
if you have seperate file redirect back with header('Location: www.xyz.com');
After reading your last comment above, use:
header('Location: www.xyz.com');
after adding to update automaticly
I have a web site with several php pages, one of them (called form.php for instance) prints with echo a form which action is sending the form itself with action=$_POST[PHP_SELF], the problem I have is due to security my web site is an Index.php page with another page include,another one and another one which is form.php.
When I click "submit" on the form the "submit" goes to Index, not to form.php, how can I solve that ? If I use the if(isset($_POST['submit'])) in the index works fine but with different results, I want this to work in the form.php page, let's say I just want to run a function, add data to mysql and show a sentence saying done, I do everything, but going through index.php and including the form.php again.
Any help ? thanks in advanced.
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.
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.