I am new in using PHP - i am trying to get the data from data sent to the Apache server using $_POST - but i am getting nothing
below is the details
i am using XAMPP on Windows 7 for setup (Apache & PHP)
and I am having two files
welcome.html which is calling welcome.php to echo the contents got from the html
Note that I have nothing reported in Apache error log file
C:\xampp\apache\logs\error.log
any idea what went wrong here
<head>
<meta charset="utf-8"/>
</head>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
<input type="submit">
</form>
</body>
and
welcome.php
<?php
error_reporting(E_ALL);
?>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
</head>
<body>
Welcome
<?php echo $_POST["name"]; ?><br>
</body>
for testing your php file. direct run this welcome.php from your localhost
like this http://localhost/welcome.php
<?php
echo 'Check your name';
?>
if you see "Check your name"; then your local server is working . else need to run local server
this is your html welcome.html file
<head>
<meta charset="utf-8"/>
</head>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
<input type="submit">
</form>
then submit your form using name text
then check your code using
<?php
error_reporting(E_ALL);
print_r($_POST);
?>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
</head>
Welcome
everything work here
Related
I have started learning php recently and have confront with this error while working on localhost. I have tried all possible solutions available on the web but haven't got ridden of the problem.
I am using VS code for text editing and installed php and apache(as the webserver) on windows 10. I have trying the code to get the input and print that on the screen but this error is showing every time.
Please help me out about this
I am including the code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FORM</title>
</head>
<body>
<!--#an example showing the working of request variable-->
<form method="POST" action="<?php echo $_server['php_self'];?>">
name:- <input type="text" name="fname" id="1">
<input type="submit" value="submit">
</form>
<?php
if($_SERVER["REQUEST_METHOD"]=="POST")
{
$name = $_REQUEST['fname'];
if(empty($name))
{
echo "name is empty";
}
else
{
echo "NAME IS ";
echo $name;
}
}
?>
</body>
</html>
I have created two simple web pages, one is written in HTML, and the second is written in PHP. In the HTML page, I include form tag with action attribute and its attribute value is index.php(second page) and index.php(second page) include $_REQUEST but no value is displayed.
html page
<html>
<head>
<title>testing of php</title>
</head>
<body>
<h3>here the value will be displayed</h3>
<form method="post" action="index.php">
please enter your name:
<input type="text" name="don"></input><br>
<input type="button" value="send"></input>
</form></body>
</html>
php page
<html>
<head>
<title>testing of php</title>
</head>
<body>
<?php
echo "hello:";
echo $_REQUEST['don'];
?>
</body>
</html>
The type should be submit not button to submit the form using post method :
<input type="submit" value="send"></input>
You need to make another input type.
Working code:
HTML
<html>
<head>
<title>testing of php</title>
</head>
<body>
<h3>here the value will be displayed</h3>
<form method="post" action="index.php">
please enter your name:
<input type="text" name="don"></input><br>
<input type="submit" value="send"></input>
</form></body>
</html>
PHP
<html>
<head>
<title>testing of php</title>
</head>
<body>
<?php
echo "hello:";
echo $_REQUEST['don'];
?>
</body>
</html>
https://www.w3schools.com/html/html_form_input_types.asp
https://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_submit
I have two files here as a test the first one which is this below and when I click submit it suppose to do the action on the next page but I want to know how to get retrieve athe $life variable from the action php file and put it in the normal html file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form class="" action="../logic/profileAction.php" method="post">
<label for=""></label>
<button type="submit" name="button">Submit</button>
</form>
</body>
</html>
Second file which is the php file:
<?php
$life ="Yo";
?>
check this code. you need to run this code in server
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<?php
include_once 'edit.php';
echo $life;
?>
<form class="" action="../logic/profileAction.php" method="post">
<label for=""></label>
<button type="submit" name="button">Submit</button>
</form>
</body>
</html>
and this is your include edit.php
<?php
$life = 'Ok';
?>
then your first file show ok when you run this code
This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 6 years ago.
I recently start the php programming. However, I encountered a problem about running a function on php file. My php file is listed as follows:
<html>
<head>
<meta http-equiv="content-type" content="text/html" />
<meta name="author" content="aaaaa" />
<title>Untitled 3</title>
</head>
<body>
<form method="post" action="Test()" >
<input type="submit" name="submit" value="submit"/>
</form>
<?php
echo "Hello";
function Test()
{
echo "Goodbye";
}
?>
</body>
</html>
After running the program, a webpage is observed with A button entitled submit and the word "Hello". However, After click on the button, the webpage "This page cannot be displayed" is observed. But I respect the word "Goodbye" is shown. I transferred the php code to another file, but the problem was not resolved.
actions in forms aren't functions like JavaScript. You are trying to run Test() on submit which isn't a thing. What you want is action to be action=" "
In reality you should be doing something like this:
<html>
<head>
<meta http-equiv="content-type" content="text/html" />
<meta name="author" content="aaaaa" />
<title>Untitled 3</title>
</head>
<body>
<form method="post" action="" >
<input type="submit" name="submit" value="submit"/>
</form>
<?php
echo "Hello";
if(isset($_POST['submit'])){
echo "Goodbye";
}
?>
</body>
</html>
If you WANT to use a function....
<html>
<head>
<meta http-equiv="content-type" content="text/html" />
<meta name="author" content="aaaaa" />
<title>Untitled 3</title>
</head>
<body>
<form method="post" action="" >
<input type="submit" name="submit" value="submit"/>
</form>
<?php
echo "Hello";
function test(){
echo "Goodbye";
}
if(isset($_POST['submit'])){
test();
}
?>
</body>
</html>
Lets say he file name is test.php where you have put all your code so the action values should be test.php
<form method="post" action="test.php" >
I have created a page linked to my databases so I can easly manipulate it
so , should I put this page on the public_html directory or there is some securised directory ?
There isn't any "securised directory" on your web server accessible only by you from your browser, you have to create an user/login system to access to the admin page you created.
There are many ways to do it, the simplest but also the less secure is to create 2 files:
index.php
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Sign in page</title>
</head>
<body>
<form action="validate_login.php" method="POST" name="loginform" novalidate>
<input type="text" name="users_email" placeholder="Username">
<input type="password" name="users_pass" placeholder="Password">
<input type="submit" value="Submit">
</form>
</body>
</html>
validate_login.php
<?php
// Get Username/Password submitted information
$email = $_POST["users_email"];
$pass = $_POST["users_pass"];
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Admin page</title>
</head>
<body>
<?php
if($email==USERNAME && $pass==PASSWORD) {
echo 'OK you are logged in';
//YOUR CONTENT HERE ....
} else {
echo '<p>Sorry, invalide username/password. Please try again.</p>';
};
?>
</body>
</html>
Change USERNAME and PASSWORD with your username and password.
Hoping to be helpful. :)