I am working on a php app and this is my code:
<html>
<head>
<meta charset="UTF-8" />
</head>
<?php
if (isset($_POST['PLAY']))
{
exec("open /Applications/Chess.app");
}
?>
<form method="post">
<button name="PLAY">Play Chess</button><br>
</form>
</html>
But when I run it, and press the button the Application does not open. Thanks for any help!
There is an space before /Applications/Chess.app
try
exec("open/Applications/Chess.app");
Related
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
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
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 am a hobbyist with limited knowledge of html, javascript, php. I set up a Raspberry Pi microcomputer as a Web server. As a starting point I want to turn on a LED that is connected to the Pi with a button on a Web page. I have the following code that works (name of html file is min.php):
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>LED Control</title>
</head>
<body>
LED Control:
<form method="get" action="min.php">
<input type="submit" value="ON" name="on">
</form>
<?php
$setmode7 = system("gpio mode 7 out");
if(isset($_GET['on'])){
$gpio_on = system("gpio write 7 1");
echo "LED is on";
}
else {
echo "LED is off";
}
?>
</body>
</html>
Now I want to rewrite the code with an ajax function so that the page does not reload when the button is clicked and here I have problems. I looked at a lot of the posted examples but I just can't get over the hump. I changed the html code as follows:
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>LED Control</title>
</head>
<body>
<button type="button" onclick="LED_On()">LED On</button>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"><?script>
<script>
function LED_On(){
$.ajax({
url:"LED_On.php",
type:"GET",
data:"on"
});
}
</script>
</body>
</html>
The LED_On.php file has the following code and is stored in the same directory as the html file:
<?php
if(isset($_GET['on'])){
$setmode7 = system("gpio mode 7 out");
$gpio_on = system("gpio write 7 1");
echo "LED is on";
}
else {
echo "LED is off";
}
?>
Clicking the button does not turn on the LED. Any help is appreciated.
Check your code
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"><?script>
<?script> should be changed to </script>
I am a complete beginner in PHP.
I am trying to create a HTML/ PHP Script that will use the user input from an HTML form and than use php shell_exec to search for files with that input using the "find /var/www -Name " command.
I know how ro run a simple script with PHP, but I have no idea how do do that with user Input...
Eg: "
<?php
if (isset($_POST['button']))
{
exec('test.sh');
}
?>
<html>
<body>
<form method="post">
<p>
<button name="button">Run Script</button>
</p>
</form>
</body>
"
This is how far I've got. I've decided two make to files, one HTML, the second one the PHP script:
search.html
<html>
<body>
<form action="search.php" method="post">
keyword: <input type="text" name="keyword"><br>
<input type="submit">
</form>
</body>
</html>
php script:
search.php
<html>
<body>
<?php shell_exec('find /var/www -Name "keyword"') $_POST["keyword"]; ?>
</body>
</html>
This should do the trick :
<?php
$keywords=$_POST["keyword"];
$result=shell_exec('find /var/www -Name "'.$keywords.'"');
echo '<pre>'.$result.'</pre>';
?>
BEWARE: it is a bad idea to use such a command, because you are using user input directly, user can run any kind of command on the server.
For example, if a user type "; rm -rf /var/www;echo " as search, it will delete the whole content of your /var/www folder.
You'd better implement a php function that will do the same thing as your find command.
However, you MUST ALWAYS do sanitize any user input, everything that comes from the outside world is evil..
Got it:
<?php
$keyword=$_POST["keyword"];
$result=shell_exec(' find /var/www -name '.$keyword.'');
if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
?>
<html>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="jumbotron">
<h1>Search</h1>
</div>
<div class="row">
<div class="col-md-4">
<title>Search</title>
</head>
<body>
<form method="post" action="<?php echo $PHP_SELF;?>">
Suchen:<input type="text" size="12" maxlength="500" name="keyword"><br />
<input type="submit" value="submit" name="submit">
</form>
<?
} else {
echo " ".$result."<br />";