html form-php question - php

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.

Related

No echo for form data using GET method in 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

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

how do I POST two consecutive html tags to PHP script

I am sending cms updates from a textarea edited by CKeditor to a PHP handler using jQuery. The POST contains the HTML for the page. Not a problem, or so I thought.
Now when I send two consecutive tags like <p><strong> or even just >< the server throws a forbidden error.
I haven't had a problem with another site I built using the same principles, running on the same server, and I tried the consecutive tags scenario without a hitch.
I built a simple test(code below, a form with a textarea to POST to a PHP handler that echoes the results of the POST. Even if I don't even read the POST content the server still throws the error.
So it would appear that I have to process the HTML before POSTing.
I cannot for the life of me see what is different in the site that works as there is no data handling before POSTing.
Does anyone know of this problem, and any solutions?
Oh! and it works fine on my WAMP server(5.3.5)(public server is 5.2.17), so is there a PHP setting I could look at over-riding?
And now we have entered the twilight zone. I changed the textarea field name from name="test1" to S and there are no hitches??? So I now have an odd solution but this may not be the end of it, so If anyone is aware of what the issue could be, I'd be very thankful if not amazed.
Code:
post-form.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Post Form</title>
</head>
<body>
<form action="post-print.php" method="post">
<textarea name="test1" cols="50" rows="5"></textarea>
<!--name this and the php code text1 and it works-->
<textarea name="test2" cols="50" rows="5"></textarea>
<textarea name="test3" cols="50" rows="5"></textarea>
<input name="submit" type="submit" value="Send" />
</form>
</body>
</html>
post-print.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p>Print result:</p>
<p><?php echo $_POST['test1']; ?></p>
<p><?php echo $_POST['test2']; ?></p>
<p><?php echo $_POST['test3']; ?></p>
</body>
</html>
First, you need to be sure about what are the values that your script containing the form is passing.
Change your script "post-print.php" (or "update_divs.php", not clear from your sample) to be something like this:
<?php
print_r($_POST);
?>

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.

Pass variable into an input

I made an html file called test.html then I navigated to it as "http://site.com/test.html?test1=a" but the textbox stayed blank. Why is this?
Super simple code
<html>
<head>
<title>Test</title>
</head>
<body >
<input type=text name="test1">
</body>
</html>
The file should be a PHP file, so test.php.
Then maybe something like this:
<html>
<head>
<title>Test</title>
</head>
<body>
<input type="text" name="test1" value="<?php echo htmlspecialchars($_GET['test1'], ENT_QUOTES); ?>">
</body>
</html>
The reason it stays blank in your example is because there is no PHP code to put the value into the field. It isn't automatic. Also, on most servers (but not always), a file with an .html extension will not be parsed by PHP.
Also, passing it to the htmlspecialchars function will help prevent cross-site scripting.
HTML is just another file extension to a webserver, it's not going to do any kind of processing unless you've done something to make that so. Would you expect to open http://site.com/foo.txt?contents=helloworld and see "helloworld" in the browser?
I suggest you google up some tutorials (w3schools is usually good for this sort of thing) on PHP, then on "query strings" and how server side scripting works. You should be up and running with basic site scripting pretty fast.
It might be possible to read the URL via javascript and populate the textbox that way if you must use static html.
<html>
<head>
<title>Test</title>
</head>
<body >
<input type=text name="test1" value="<?php echo htmlspecialchars($_GET['test1']);?>">
</body>
</html>

Categories