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

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.

Related

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

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;
?>

PHP Autocomplete using SQL [duplicate]

This question already has answers here:
jQuery autocomplete with callback ajax json
(6 answers)
Closed 1 year ago.
I'm new to PHP and trying to implement an autocomplete as a proof of concept for a project for work.
The following is the code for the web page.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test</title>
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- jQuery UI library -->
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<!-- Initialize autocomplete -->
<script>
$(function() {
$("#skill_input").autocomplete({source: "search.php",});
});
</script>
</head>
<body>
<div class="container">
<h4>Auto complete Input for countries</h4>
<form method="post" action="submit.php">
<label > Your Skills:</label>
<input type="text" id = "skill_input" name="skill_input" placeholder="Start typing..."/>
<input type="submit" name="submit" value="SUBMIT">
</form>
</div>
</body>
</html>
The page displays as it should. As I type a valid search term for what is in the DB nothing happens. e.g. "Ger"
I'm running the site on xampp.
My DB is loaded with countries.
I put an echo in my DB module to see if it is reached. It is not displaying unless I use the URL of the DB module directly. When I go to the DB module directly using the URL http://localhost:8012/Managers/search.php?term=Ger
I receive the following
we are in the search php file
[“Algeria”,”Germany”,”Niger”,”Nigeria”]
This seems to indicate that the DB module is working e.g. accepting a search value, accessing the DB and returning data as expected.
So it appears to me that the script
$(function() {
$("#skill_input").autocomplete({
source: "search.php",
});enter code here
});
</script>
is not sending any data to the "search.php" page.
My question is why? Can anyone help me understand why the page is not sending any data to search.php? I would assume that it is not even calling search.php as I'm not seeing the echo message unless I use the URL directly.
The return of data is resolved.
/* Toss back results as json encoded array. */
$json_array = array();
$json_array = json_encode($return_arr);
echo json_encode($return_arr);
The above code coverts the response from the DB to json and then returns the data.

What program is used to process php files within an html context?

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!

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