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.
Related
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!
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
I am a very new to web programming and perhaps this questions might seem to obvious. I have a form on the website and a button. When the button is pressed I want to call external program (Linux executable) which is located on the server, and pass all the text data from the filled form on the page to that program as arguments, and then get the output back to user. For ex: (./myprogram username userjob ...).
How can this be implemented? What language should I use? Javascript, PHP, Python?
Thank you
You can execute the program with the system call and add the arguments posted by the user to the end of it. It would look something like this:
$theResults = system(escapeshellcmd('./myProgram '.$_REQUEST['arguments']));
echo $theResult;
A full working example would be something like this:
<?php
if(!empty($_REQUEST['arguments'])){
$results = system(escapeshellcmd('./myProgram '.$_REQUEST['arguments']));
}
?>
<html>
<head>
<title></title>
</head>
<body>
<?php
if(!empty($results)){
echo $results;
}
?>
<form method="post" action="">
Your Arguments: <input type="text" name="arguments" value="" /><input type="submit" name="Submit" value="Submit" />
</form>
</body>
</html>
You can simply use php for that:
<?php exec("./yourscript.sh");
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.
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>