What determines whether firefox will open a file (PHP or HTML) in the browser
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
What determines whether firefox will open a file (PHP or HTML) in the browser
Using Ubuntu 18.04
SAME PAGE PROCESSING
Quote:
How can you process a form on the same page vs using a separate process page.
I got this code, copied here from the internet, as an example of having a form and php open on same page.
I am trying to open it as: test2.php. It does not work. A window comes up asking if you should open the file with firefox.When you say yes the samw window asks the saqme question. Over and Over and Over.
Code:
<?php
//Form submitted
if(isset($_POST['submit'])) {
//Error checking
if(!$_POST['yourname']) {
$error['yourname'] = "<p>Please supply your name.</p>\n";
}
if(!$_POST['address']) {
$error['address'] = "<p>Please supply your address.</p>\n";
}
//No errors, process
if(!is_array($error)) {
//Process your form
//Display confirmation page
echo "<p>Thank you for your submission.</p>\n";
//Require or include any page footer you might have
//here as well so the style of your page isn't broken.
//Then exit the script.
exit;
}
}
?>
<form method="post" action="<?=$_SERVER['PHP_SELF']?>">
<?=$error['yourname']?>
<p><label for="yourname">Your Name:</label><input type="text" id="yourname" name="yourname" value="<?=($_POST['yourname'] ? htmlentities($_POST['yourname']) : '')?>" /></p>
<?=$error['address']?>
<p><label for="address">Your Address:</label><input type="text" id="address" name="address" value="<?=($_POST['address'] ? htmlentities($_POST['address']) : '')?>" /></p>
<p><input type="submit" name="submit" value="Submit" /></p>
</form>
It sounds as if you may be trying to open the file with your browser from your filesystem, or perhaps by simply clicking on it, but NOT from your web server (i.e. via HTTP request).
Neither Firefox nor your DE knows anything about PHP. Firefox decides whether to display the content itself or ask about other applications based on the mime type and/or response headers returned by the server. Your DE relies on mime type. When you open it as a file instead of via HTTP request there are no response headers and the PHP code is not executed but simply opened as a text file and Firefox may ask what to do with it if you have not set a PHP handler (but even if you have set a handler, it is still just text, not executed code).
So, first question is how exactly are you trying to open it?
Same as previous poster:
Firefox cannot parse PHP, full stop (even though some web pages end in .php, it's still server-side scripting).
Even if you somehow manage to shoehorn it into opening that file, it will only open as text. And what would be the use in that.
You want to install LAPP or LAMP stack on your machine.¹ There are many guides on the Internet describing how to do it and with Ubuntu it’s probably just a matter of a few simple ‘apt install’ commands. Once you have Apache running with PHP configured, you’ll be able to open the script through http://localhost/ link.
¹ You probably can skip the database for the time being to make things a little bit simpler.
Basically test3.php is a standalone all in one script. When you "run" the script from the browser you see the empty form (will ignore the Array() and all the other errors for now). When you enter something in the text box and press enter, the script is called and starts from the top which reloads the entire page. The variable Fname is assigned the string you entered in the text box ( $Fname = $_POST["Fname"]; ) and then displayed below the form using the echo ($fname) statement;. All the other stuff is CSS.
ajax in a nutshell is a way to send and retrieve data from a server (database in your case) asynchronously (in the background) without interfering with the display of the existing page which allows you to change content dynamically without the need to reload the entire page. I'm not much of a javascript programmer but java is just calling the test3.php script versus the web browser actually running the CSS commands which is why you see that text from your partialname2.php image.
Since I am not much of an ajax/javascript programmer I believe your javascript will need to create the dynamic partial name form in your selectQuery.php. Hopefully others will reply with some example code.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.