No echo for form data using GET method in PHP - php

Fairly new to PHP. Have been trying a simple program to get data from 2 fields and display it using GET method.
Heres the HTML code
<html>
<head>
<title>Simple Form</title>
</head>
<body>
<form action="send.php" method="get" id="sample">
Name:<input type="text" name="user"/>
Message:<input type="text" name="message"/>
<input type="submit"/>
</form>
</body>
</html>
Heres the PHP code:
<html>
<body>
Welcome <?php echo $_GET["user"]; ?>
Message <?php echo $_GET["message"]; ?>
</body>
</html>
The GET method fetches the data as a QueryString in address bar of browser, but doesn't display anything in browser window.

The code works perfectly. Reinstalling WAMP server solved the issue.

You need to start the server.
Go to your directory where the index.html file of your website lives, then run the command line php -S localhost:5000.
5000 is the port where php is listening to, you can put any value there....
Install php if you haven't.. Or Wamp

Related

When using PhpStorm 10, how can I get the browser to recognize the 'input' name array?

I'm a novice learning PHP and am stuck on a basic issue. It looks like a configuration issue. I reviewed stackoverflow, tutorials, and PhpStorm documentation, but was unable to find a simple answer.
I'm trying to get HTML form data to post a message upon submitting the form. There are two php files, the example.php has the php script, and the welcome.php file has the HTML with the php echo script. The HTML text information is returned, but Chrome throws an error notice, Notice: Undefined index: name in ... welcome.php on line 4, related to the submitted name and email array.
PhpStorm gives me a warning on the example.php file, form input
without associated label or form attribute. My conclusion is that PhpStorm is not associating the two files.
I'm using PHP 7.0.0, with C:\wamp64\bin\apache\apache2.4.17\htdocs
example.php
<!DOCTYPE HTML>
<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
welcome.php
<!DOCTYPE HTML>
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
PhpStorm has nothing to do with the error.
If you just go to welcome.php page it will give an error because there is no $_POST submission. You can check if there is any submission first.
Welcome.php
<!DOCTYPE HTML>
<html>
<body>
Welcome <?php if(isset($_POST['name'])){ echo $_POST["name"]; }?><br>
Your email address is: <?php if(isset($_POST['email'])) { echo $_POST["email"];} ?>
</body>
</html>
I'm following a beginners tutorial. I tried a basic echo, nothing displayed in the browser. It looks like this is part of my initial problem. No errors, no problem with the code. That's why I thought this was a problem with PhpStorm.
learnphp.php file
<!DOCTYPE HTML>
<html>
<head>
<title>Information Gathered
<body>
<?php
echo "<p>Data processed</p>";
?>
</body>
</html>
This was a configuration issue. PhpStorm was defaulting to the PhpStorm port and not port 80.
PhpStorm wasn't properly configured to work with the server. I uninstalled wamp and installed xampp, that didn't fix the problem, but gave me more control.
In Settings, Build, Execution, Deployment:
Type: Local or mounted folder is required because my project is on my D: drive, and server is on my C: drive
Mappings: Use this server as default button must be selected
Web path on server 'xampp': must be the project file folder

POST and GET are unable to display user input values from HTML form

I have just started to learn HTML and PHP, but have run into a road block while following beginner tutorials. I am attempting to have the user input numbers into a form on the HTML page, then press submit to redirect to a PHP page that displays the values. The PHP page shows up and successfully displays prepared text but displays nothing for the values.
HTML code:
<html>
<body>
<head>
<title>Practice Page</title>
</head>
<h1>Numbers</h1>
<p>Put numbers in the boxes</p>
<form action="welcome.php" method="post">
NumOne: <input type="text" name="oynumone"><br>
NumTwo: <input type="text" name="oynumtwo"><br>
<input type="submit" value="Submit" id="SubmitRegister" name="submit" />
</form>
</body>
<html>
PHP code:
<html>
<body>
Number one is <?php echo $_POST["oynumone"]; ?><br>
Number two is <?php echo $_POST["oynumtwo"]; ?>
</body>
</html>
Both of the files are simply in the same folder in my documents. I understand that I need a server to host PHP content; I have downloaded MAMP for this, but I don't yet understand how to use it.
Any help would be most appreciated.
Store both file name with .php extension AND/OR update Welcome.php like below -
Welcome.php
<?php
if isset($_POST['submit'])
{
$oynumone = $_POST['oynumone'];
$oynumtwo = $_POST['oynumtwo'];
echo "Number one is ".$oynumone;
echo "Number two is ".$oynumtwo;
}
?>
Also check this

PHP file doesn't run

I have this two files:
index.html
<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
And welcome.php
<html>
<body>
Welcome, <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
This is example from there
When the user fills the form and hits "enter" it should display:
Welcome, the_name_you_enter
Your email address is address_you_enter
But for me it only displays welcome.php source code (I am using Safari 7).
Does anyone knows why?
It sounds like your calling up the page from a server that is not executing php.
This usually happens because the PHP file is not executed on a web server or PHP is not enabled on your webserver.
You are probably trying to access the file directly using file://
Take a look at MAMP (I am assuming you are using OS X)

html form-php question

This is my html form and below this i included my php text.
But I am not getting correct output,i don't no where the problem is ?
I also included the output ,please suggest me what shuld i do?
<html>
<head>
<title>
Entering data into text
</title>
</head>
<body>
<h1>
Entering data into text
</h1>
<form action="text.php" method="post">
What is ur name ?
<input type="text" name="data" />
<input type="submit" value="send" />
</form>
</body>
</html>
This is my php text:
<html>
<head>
<title>
Reading data from textfields
</title>
</head>
<body>
<h1>
reading data from text field
</h1>
Thanks for answering,
<?php echo $_POST["data"];?>
</body>
</html>
Output:
reading data from text field
Thanks for answering,
problem is that ,data send is not included after response of sever
please help me as fast as possible
I can only speak for my own experience, but this works on my server. I'd suggest, then, that one of the following is true:
Your server isn't set up to handle php (though this would surprise me), also, as #gAMBOOKa noted (in the comments), if your server's not set up to handle php the script wouldn't output anything other than the raw text-contents of the php script, literally "<?php echo $_POST["data"];?>".
You're trying to access the pages through the filesystem (file:///path/to/file.html), rather than through your server (http://localhost/file.html).
If '2' is correct, move your web-page and php script into a directory within your server's document root, on *nix this could be something like /var/www/directoryName/ and access the page via http://localhost/directoryName/dataEntryForm.html. If you're on Windows, with IIS it could be C:\inetPub\directoryName\ accessed, as above, with http://localhost/directoryName/dataEntryForm.html.
Incidentally, please forgive me for not linking to a demo of the page running, it's just that I'd prefer not to run the risk of exposing my server to, presumably, vulnerable scripts.
Your full code is like this and I tested it, working perfectly.
<html>
<head>
<title>
Entering data into text
</title>
</head>
<body>
<h1>
Entering data into text
</h1>
<form action="text.php" method="post">
What is ur name ?
<input type="text" name="data" />
<input type="submit" value="send" name="btn_save" />
</form>
</body>
</html>
text.php
<?php
if(isset($_POST['btn_save']))
{
$data=$_POST['data'];
}
?>
<html>
<head>
<title>
Reading data from textfields
</title>
</head>
<body>
<h1>
reading data from text field
</h1>
Thanks for answering,
<?php echo $_POST["data"];?>
</body>
</html>
working perfectly.

Run a batch file using php

Below is my piece of code , on giving the tool name as the input and pressing submit , the batch file corresponding to that tool shall be executed.
<html>
<head>
<title>My Form</title>
</head>
<body>
<form action="batch.php" method=post>
Which tool you would like to use:
<br> <input type="text" name="ToolName">
<p>
<input type="submit" name="submit" value="Please wait!">
</form>
</body>
</html>
BATCH.php
<html>
<head>
<title>Perv!</title>
</head>
<?php
$ToolName = $_REQUEST['ToolName'] ;
?>
<p>
Hi <?php print $ToolName;
//exec("cmd/c D:\workspace\execute.bat");
exec("C:\\wamp\\www\\test.bat");
//system("test.bat");
//system("cmd /c D:\\workspace\\execute.bat");
?>
</body>
</html>
I am using Apache /Windows.
Please suggest any help will be appreciated.
As I already commented, what you describe seems to be a problem of your batch file. But anyway, is this file supposed to just do something or to output stuff that should be displayed?
If the later is the case, note that exec() only returns the last line of the output. You can get all the output be providing another variable to get all the output. The official php documentation of the exec() function tells you have to do this.
as far as i could understand your question, you can try this:
system($ToolName);
You may want to specify correct path for the $ToolName variable.

Categories