Paul Bergström
Paul Bergström

Reputation: 253

Making variable from HTML-file work in PHP-file

I have two rather simple files. The first is an HTML-file like this:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<html>
<body>

<form action="test.php" method="post">
Search for: <input type="text" name="search" />
<input type="submit" name="submit" value="Search" />
</form>

</body>
</html>

The second file is test.php and it looks like this:

<?
       $filepath = "/usr/sbin";
       exec("ONE $search -command $filepath ");
       fopen($filepath, rw);
?>

My problem is that I want to use the argument "search" given in the HTML-form as value of variable in the PHP-script. ONE is a search script I made that takes one argument and I want it to be "$search".

Could this be done and if so how?

Many thanks in advance.

Upvotes: 0

Views: 137

Answers (2)

Just do this:

exec("ONE " . $_POST['search']. " -command $filepath ");

UPDATE:
You have another error, your following line:

fopen($filepath, rw);

should be like this:

fopen($filepath, "rw");

cause the second parameter to fopen() should be passed as a string.

UPDATE 2:
So as it seems, the OP want the output of the command to be printed on the page, for that you have to use passthru() instead of exec() , like so:

passthru("ONE " . $_POST['search']. " -command $filepath ");

Upvotes: 1

Horen
Horen

Reputation: 11382

You can access that variable by using $_POST['search']

Before you use it in a shell call you should make sure that it won't damage your system.

Upvotes: 1

Related Questions