This is an example of: When php cant work in some websites.
I was trying to make a Search_Query but it doesn’t work. Even inspect element doesn’t work. They made the code like:
<!--<?php echo "hello" ?>-->
i do not know why but it happens.
here's my files:
index.html:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Home - Yantoxsoft</title>
<!-- Load external CSS styles -->
<link rel="stylesheet" href="styles.css">
<!-- Load website icon -->
<link rel='shortcut icon' href='icon.jpeg'>
</head>
<body>
<form action='search.html'>
<label for='search_query'>
Search:<input name='search_query'><input type="submit">
</label>
</form>
<!-- Load external JavaScript -->
<script src="scripts.js"></script>
</body>
</html>
search.html:
<form action='search.html' method='POST'>
<label for='search_query'>
<input name='search_query'>
</label>
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$search = $_POST['search_query'];
if (empty($search)) {
echo "No Results for: " + $search;
} else {
echo "results for:" + $search;
}
}
?>
and do not answer with .php files because they are not supported :/
Because they only make .css, .js, and .html files and image or gif files. Why not python, lua, mp4, or php? Who knows.
A PHP Script will never work in a file with .html extension. You already said your hosting provider doesn't allow .php. You don't have any other problem. You either forget about your search functionality or change your host!
Please save PHP file with .php extension and use html tag inside as: echo "<h1>Hello Dev!</h1>";
i.e after saving your code in .php format
<?php
echo "<form action='search.html' method='POST'>
<label for='search_query'>
<input name='search_query'>
</label>
</form>";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$search = $_POST['search_query'];
if (empty($search)) {
echo "No Results for: " + $search;
} else {
echo "results for:" + $search;
}
}
?>
Your HTML files won't be processed by PHP engine but You've saved everything in an html file so it's clear why it doesn't work.
Change the extension from .html to .php and if your hosting service provider doesn't support PHP, you have to find another one.
Related
I have this url in classic asp:"http:/blablabla/123.asp?id=1293". My question, is there a way to pass the id number to a external php script without using the form and submit, or that is only way to do it??
My data.php script:
<?php
$xxx = $_POST["xxx"];
//... some code
$gantt->render_complex_sql("SELECT * FROM gantt_tasks WHERE something = '".$xxx."'" , "id", "start_date,duration,text,progress,parent","");
?>
My "123.asp?id=1293" page:
<html>
<head>
// .. scripts and title
</head>
<body>
<form id="form1" method="post" action="data.php">
<input type="hidden" name="xxx" value="Request.QueryString("id")" />
</form>
<div id="gantt_here" style='width:100%; height:100%;'></div>
<script type="text/javascript">
gantt.init("gantt_here");
gantt.load("data.php");
</script>
</body>
</html>
And i dont want to use the "Response.Redirect" page either.
You can do this:
UPDATE:
gantt.load('data.php?id=<%= Request.QueryString("id") %>');
But it sounds very strange using old asp files and php files in the same project.
First of all this is not my code, I just need it changed a little.
I need to know how to write messages onto the same file where the user posts the message.
Here is one page where the user can post their message:
<html>
<head>
<title>Form to Flat File</title>
</head>
<body>
<form action="sendinfo.php" method="get">
Your Name:<br />
<input type="text" name="name"><br />
Your Message:<br />
<textarea name="message"></textarea><br />
<input type="submit" value="Send Info">
</form>
</body>
</html>
And here is the other that writes the message onto a PHP file:
<html>
<head>
<title>Form to Flat File</title>
</head>
<body>
<?php
include('config.php');
$user = $_GET["name"];
$message = $_GET["message"];
print("<b>Thank You!</b><br />Your information has been added! You can see it by <a href=savedinfo.php>Clicking Here</a>");
$out = fopen("savedinfo.php", "a");
if (!$out) {
print("Could not append to file");
exit;
}
fputs ($out,implode,("\n"));
fwrite($out,"<b>$user</b><br />$message<br /><br />");
fclose($out);
?>
</body>
</html>
Pretty much I just want everything on one page, I got close to doing that but it won't let me write onto the same page. I'm sure it's possible I'm just nowhere near experienced enough. Please help!
What you want is to put content of both files in a single file, but execute the content of the second file only if form has been submitted.
First of all, change the form's method value to POST and replace all references to $_GET with $_POST
Then create a single file containing
<html>
<head>
<title>Form to Flat File</title>
</head>
<body>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// here put content of the file that stores form values in a file
// just remove all html code and leave only PHP code
}
?>
// here put content of the file that displays the form
// just remove HTML, HEAD and BODY tags first
</body>
</html>
I have been following the php tutorial here
CODE
Here is my html file:
<!DOCTYPE html>
<html>
<head>
<link rel=”stylesheet” type=”text/css” href=”style.css”>
<form action="postForm.php" method="post">
<TextArea name="microBlog" id="microBlog" cols="30" rows=“10"></TextArea>
<input type="submit">
</form>
</head>
<body>
<?php
require_once 'meekrodb.2.3.class.php';
DB::$user = 'root';
DB::$password = '';
DB::$dbName = 'MicroBlog';
$results = DB::query("SELECT post FROM MicroBlog");
foreach ($results as $row){
echo "<div class='microBlog'>" . $row['post'] . "</div>";
}
?>
</body>
</html>
This yields the following:
However if I copy the php code into a new postForm.php file and click "Submit" (as you can see the action is postForm.php), it works.
I get my blank screen with 3 words (from the database).
The problem is it is a brand new blank page and I do not want that.
PROBLEM
Why is it that the code works outside the html file, but not inside the html file. Why do I get ".row['post']."";} ?> when inside the html file but I get perfect output when the php exists in its own php file?
There is clearly nothing wrong with the code, so what could it be?
It really confuses me. Thanks for any answers.
Change your file extension .html into .php or .phtml. It will solve your problem.
You are writing a php code inside html file. html file doesn't evaluate php code.change the extension of file to .php instead of .html by doing so you write both html and php code inside that file.
Reason: 1. An html file does not support php scripts inside it and thus anything written will not be executed and will only be treated as an html markup.
Solution:
1. Just save the .html file as .php file and you are done!(very simple).For example if your file name is index.html, just save it as index.php and all the php scripts inside will be executed.
index.php:
<!DOCTYPE html>
<html>
<head>
<link rel=”stylesheet” type=”text/css” href=”style.css”>
<form action="postForm.php" method="post">
<textArea name="microBlog" id="microBlog" cols="30" rows=“10"></textArea>
<input type="submit">
</form>
</head>
<body>
<?php
require_once 'meekrodb.2.3.class.php';
DB::$user = 'root';
DB::$password = '';
DB::$dbName = 'MicroBlog';
$results = DB::query("SELECT post FROM MicroBlog");
foreach ($results as $row){
echo "<div class='microBlog'>" . $row['post'] . "</div>";
}
?>
</body>
</html>
I have a simple form and I'm trying to pass the form variable to php and output the value. I have tried to solve this myself with the almighty google but wasn't successful. The html form code is as follows
<html>
<head>
<title>Form</title>
</head>
<body>
<form method="post" action="test1.php">
<input type="text" name="username">
<input type="submit">
</form>
</body>
</html>
Then the php to handle the form is:
<html>
<head>
<title>Form</title>
</head>
<body>
<?php
echo "<h1>Hello " . $_POST["username"] . "</h1>";
?>
</body>
</html>
The output I'm getting no matter what I type into the html form is , Hello " . $_POST["username"] . ""; ?>
I don't know why it also outputs the ending semi colon and ending php tag also, maybe this is evidence of what's going wrong here?
PHP is
misconfigured or
not configured or
not working or
not working within HTML files.
You have to configure your webserver that it parses PHP inside HTML files, see here for example:
=> Server not parsing .html as PHP
The syntax is fine, try to write a sample code snippet like below
<?
$a = "hello word!";
echo $a;
?>
and check if php is working.
Very simply, as a browser style UI, I'm trying to read two parameters (provided by user) in two textboxes, save them in a plain text file (specifically a csv but that's not important) on the server but not stopping there, to ensure that these has saved correctly, and as feedback to the user, I want to read the newly saved parameters back from the file into two other textboxes on the same page.
When the page loads, jquery successfully populates the "currently saved settings" textboxes with the values read in from the server csv file using php. When I enter new values and then click the [submit] button to save these values, the server file gets updated successfully.
And it is the next steps where the problem arises, I can use php to read the newly stored values back in from the server file and "alert" them to check that they are correct but the jquery lines to update the "currently saved settings" will not update. I have to refresh the webpage to get these textboxes to update. I should say that the "alerts" display the correct (newly saved) values so everything up to that point works fine it's just the following two jquery lines that work on page load don't seem to get executed at this point.
Hopefully there's something dead simple I'm missing here.
(The csv file itself is simply two parameters used by a complete separate and unrelated piece of software.)
Help much appreciated.
php file as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>System Settings</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js" type="text/javascript"></script>
<?php
$SystemSettings = explode(",",file_get_contents('Data/Settings.csv'));
?>
<script type="text/javascript">
$(document).ready(function () {
$("#txtStoredParam1").val("<?php echo $SystemSettings[0] ?>");
$("#txtStoredParam2").val("<?php echo $SystemSettings[1] ?>");
$("#btnSaveSettings").button();
});
</script>
</head>
<body>
<?php
if(isset($_POST['submit']))
{
$File = "Data/Settings.csv";
$Handle = fopen($File, 'w');
$Data = $_POST['Param1'] . "," . $_POST['Param2'];
fwrite($Handle, $Data);
fclose($Handle);
$SystemSettings = explode(",",file_get_contents('Data/Settings.csv'));
?>
<script>
// alert("<?php echo $SystemSettings[0] ?>");
// alert("<?php echo $SystemSettings[1] ?>");
$("#txtStoredParam1").val("<?php echo $SystemSettings[0] ?>");
$("#txtStoredParam2").val("<?php echo $SystemSettings[1] ?>");
</script>
<?php
}
?>
<form id="Form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="SettingsForm" target="iFormResponse">
<h2>Parameter 1:</h2>
<input id="txtParam1" type="text" name="Param1" />
<h2>Parameter 2:</h2>
<input id="txtParam2" type="text" name="Param2" />
<p> </p>
<p><input id="btnSaveSettings" type="submit" value="Save Settings" name="submit" /></p>
<p> </p>
<h3> Currently Saved Settings: </h3>
<p> <label id="lblParam1">Parameter 1: </label><input id="txtStoredParam1" type="text" name="StoredParam1" />
<label id="lblParam2">Parameter 2: </label><input id="txtStoredParam2" type="text" name="StoredParam2" /></p>
</form>
<iframe name="iFormResponse" width="300" height="200" Style="display:none;"></iframe>
</body>
</html>
Your first script block used $(document).ready() whereas the second does not. Therefore, the second block runs first and is overridden by the second.
Delete the second block and move the code for the first block to the end of the page so that you have only one script block that is reused in both cases.
But since you are using forms and PHP, why not just set the value of the input?
<input id="txtParam2" type="text" name="Param2" value="<?php echo $systemSettings[0];?>" />