This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 6 years ago.
This is my code where I intend to handle the PHP form data on the same page.
However the PHP script doesn't get executed and instead all PHP code is rendered as comments when inspected.
<!DOCTYPE html>
<html>
<head></head>
<body>
<?php // php code ?>
//html code
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<br><br><br>
<input type="text" required name="username" placeholder="Username" class="forminput">
<br>
<span><?php echo $nameErr; ?></span>
<br>
<input type="submit" value="Sign Up" class="forminput">
</body>
</html>
How can I execute the php script in browser? All files are in root directory.
You possibly need a XAMPP server to execute your php code even the file extension you have given as .html.
If your file contain the php code it will need a web server(XAMPP) to execute the process.
Hope this tutorial will help you out with Use XAMPP to run php program
You can't execute PHP code in the browser. You need a server that can handle PHP. I suggest you start with an all in one LAMP stack that supports PHP out of the box.
Try this one:
XAMPP
Related
This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 3 months ago.
I'm trying to make a simple search engine (currently using 10 random html files I've made) but I can't get the php echo to tell me I search results (which I'm using to verify that the php file knows what the search query is.) I tried using just php
This V
<?php echo $_GET["query"]; ?>
I tried PHP in HTML
<html>
<body>
<p> Search: </p> <?php echo $_GET["query"]; ?><br>
</body>
</html>
But none if it worked. Here's the code for the HTML file.
<html>
<head>
<title>Search Test</title>
</head>
<body>
<form action="Searching.php" method="post">
Search: <input type="text" name="query">
<input type="submit">
</form>
</body>
</html>
When you run the search engine and type your query the php files shows up just showing the contents of the php file. (If its an html file with php in it its just "Search:" so the query isn't showing.) I expect it to just show what my search query was.
Since you’re sending the form over POST, you would need to use $_POST instead of $_GET.
Also, your current implementation is vulnerable to cross-site scripting. You should use htmlspecialchars when you echo content you cannot trust.
This question already has answers here:
Why shouldn't I use mysql_* functions in PHP?
(14 answers)
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 2 years ago.
When I click a button to insert the data into the database by implementation of PHP code , but the problem is that it opens a new tab and shows PHP codes
html code
<html>
<body>
<form action="InsertStudent.php" method="post">
Student Id: <input type="text" name="SId" />
Student Name:<input type="text" name="SName" />
Marks: <input type="text" name="marks" />
<input type="submit" value= "Insert"/>
</form>
</body>
</html>
PHP code
<?php
$con = mysql_connect("localhost","root","1234");
if (!$con)
{
die('Could not connect:'.mysql_error());
}
mysql_select_db("my_db",$con);
mysql_query("INSERT INTO Student(StudId,StudName,Marks)
VALUES ('9876543', 'Ahmed', '90')");
mysql_query("INSERT INTO Student(StudId,StudName,Marks)
VALUES ('12344556', 'Mohammed', '95')");
mysql_close($con);
?>
every php script must be run on server. In your case you are not using server. You should install xamp or wamp server and then run your file on localhost.
step 1: download and install xamp from https://www.apachefriends.org/
step 2: copy or move your folder which contain the html and php file to c:\xamp\htdocs directory
step 3: after installation open the control panel and start apache server
step 4: open browser and type url localhost/your_folder_name
note: the folder name should not contain spaces or '-'. Name your html file as index.html
I'm just following w3schools like a normal person
For me getting php to work is harder than learning the language itself...
If somebody could please provide an extensive guide on common problems such as this one that would be heavily resourceful
I'd also like to know the ins and outs of running php scripts within an html context, not having the php extension on the browser would be preferred in most cases
I can't get the following script to run upon submitting the form. It ends up opening up a window asking me which program should be used to run the php file.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="welcome.php" method="get">
Name: <input type="text" name="name"> <br>
E-mail: <input type="text" name="email"> <br>
<input type="submit">
</body>
</form>
Opening the php file using firefox accomplishes the same thing.
If so, which program should I use? or do I need to update some configuration
in order to get this simple script to work
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
One of the easiest ways to get PHP up and running for a newbie would be to use XAMPP. See this Wikihow article on how to get that done: https://www.wikihow.com/Set-up-a-Personal-Web-Server-with-XAMPP
Good luck!
I created a contact form for my website. When I click the submit button, it just shows the PHP code instead of the message it is supposed to show, like the text information the user inputs into the form.
Here is the HTML code for the form:
<html>
<link href="contact.css" rel="stylesheet" type="text/css" />
<head>
<title>Contact Us</title>
</head>
<body>
<form action="contact.php" method="post">
<div id="ContactForm">
<fieldset>
<h4>Contact Parquest:</h4>
<label class="labelone" for="name">Name:</label>
<input name="name"/>
<label for="email">Email: </label>
<input name="email"email"/>
<label for="commens">Comments: </label>
<textarea name="commens"></textarea>
</fieldset>
<fieldset>
<input class="btn" type="submit" value="Send Email"/>
<input class="btn" type="reset" value="Reset Form"/>
</fieldset>
</form>
</div>
</html>
I couldn't post the PHP code, because it just doesn't show when I try, so here's a screenshot:
There is no problem to your code.. The problem is on your environment.. I guess you are not running the html file through a server..
If the url on your browser looks like these:
file:///c:/path/to/your/file/page.html
then you are doing it wrong.. in order to run .php scripts, you need a web server like apache or nginx... the url of should be like these
http://localhost/path/to/file/page.html
then the php file should run as expected..
php files are interpreted scripting language and thus it needs an interpreter in the server in order to run.. if it is just browsed in the browser without a server, it will just output the code inside..
You need a web server to run php scripts.
Try installing wamp and then run your page under localhost.
I have executed the given code. It's working fine on my local server. Conventionally it should print the value inputs posted by form on contact.php.
But the thing I noticed in your PHP code is the variable name is $commets, instead of $comments.
I faced the same problem and when I tried starting my own server it worked.
when you are using Windows, open cmd and type in this;
php -S localhost:4040;
you will see something like this
PHP 8.1.1 Development Server (http://localhost:4040) started
meaning you have started your own server, then you can copy the link found in the parenthesis
so you copy say this "http://localhost:4040" and paste it in your browser then you can now direct it to your html document like this
http://localhost:4040/Desktop/Projects/index.html
now your form should work well with your php script when you submit
i had the same issue, even if appache & mysql were running on my computer.
in the html file, i wrote :
form action="http://localhost/file.php" method="POST"
instead of :
form action="file.php" method="POST"
It seems like connecting HTML forms to php files only works when you download wampserver and turn on all services...
Here's how it worked for me:
You can download wampserver from here: http://www.wampserver.com/en/ (follow instructions)
I saved it to the C: drive on my computer.
Next, you can create a php file and an html file both in the 'www' folder of the wamp folder in whatever drive you put it in. Copy the form code into the HTML file, and the php code into the php file.
Finally, go to 'localhost/yourhtmlname.html' and fill out the form. It should work as normal.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
php $_POST array empty upon form submission
I am trying to have a form filled out, then the data displayed on another page. The first document is this
<html>
<head>
</head>
<body>
<form action="testerpage.php" method="post">
Name: <input type="text" name="testname">
<input type="submit">
</form>
</body>
</html>
The other page (testerpage.php) is this
<html>
<body>
<?php
echo $_POST["testname"];
?>
</body>
</html>
Why won't testerpage display the information from the first page(named welcome.php)? It doesn't work with "get" either
Given that you have untouched PHP code in your HTML output, it turns out PHP is disabled on your server so PHP code is not executed at all. Consult your hosting provider technical support on enabling PHP on server.