<<<_END What exactly does this do? [duplicate] - php

This question already has answers here:
PHP heredoc syntax
(3 answers)
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Closed 1 year ago.
I'm a college student trying to do one of the exercises from the book. The exercise is typed below. I typed it in exactly as my textbook said too. What is the purpose of <<_END at the beginning and _END; at the end? When I did it this way my html didn't work correctly. When I did it like the instructor did in his lecture it worked. What he did was put all PHP in separate sections . What is the best way to use PHP, HTML5, JavaScript and CSS3 all in one page? Or should I be linking my HTML page to external JavaScript, CSS3, and PHP pages?
My end goal for this assignment is to build a login page and a create a new account page that is linked to my database.
Any and all tips/help is very much appreciated!!
<?php //from the book page 266
echo <<<_END
<html>
<head>
<title>PAGE 266, 267</title>
<body>
<form method="post" action="formtest.php">
What is your name?
<input type="test" name="name">
<input type="submit">
</form>
</body>
</html>
_END;
?>

Related

The PHP echo function isn't working on safari HTML [duplicate]

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.

PHP downloading instead of running [duplicate]

This question already has answers here:
Apache is downloading php files instead of displaying them
(27 answers)
Closed 1 year ago.
I am working on visual studio code making a few web pages and I need to send html form data from one to another. I am using the get method but when I submit the form the PHP file downloads instead of running, is there a way to fix this?
<form action="login.php" method="get">
<p class="normal" id="samelinechild">Dora the</p>
<input name="verification" id="very" type="text">
<p class="normal"id="samelinechild">explorer</p>
<input type="submit">
</form>
If you send data use POST method not GET. I don't know if this will fix the problem but it's the rule.

How to run a php funtion in a html file? [duplicate]

This question already has answers here:
Call PHP function from url?
(14 answers)
What is the difference between client-side and server-side programming?
(3 answers)
Closed 3 years ago.
I want to do operation to a database that is running on xampp in my index.html I have the following code
<script src="oPBD.php" async defer></script>
<h1>This is a title</h1>
<form action="opBD.php">
<input type="submit" value="Do stuff" name="Button">
</form>
And this works fine, howevewer I would like to put all the code in opBD.php in a function called function1 for say something and run in html when needed. But How I do that.
I would like to use something like:
<script src="oPBD.php" async defer></script>
<h1>This is a title</h1>
<form action="opBD.funtion1().php">
<input type="submit" value="Do stuff" name="Button">
</form>
I don't find how to do this. Could you guys help me?
Can you just create a new file opBD.functionName.php and then use that in your form action? Otherwise your only real option is to use an MVC (Model View Controller) framework like Laravel or similar which would let you create real URLs for this kind of thing (eg. /user/update or something).

All of my PHP code coming as comments in HTML [duplicate]

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

Issue with forms in PHP [duplicate]

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.

Categories