Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Use a form with two submit buttons that share a name and have different value attributes. The browser sends the clicked button’s value to myPHP.php, where PHP reads it from $_GET:
<form action="myPHP.php" method="get">
<button type="submit" name="param" value="1">Run with 1</button>
<button type="submit" name="param" value="2">Run with 2</button>
</form>
The requests will be myPHP.php?param=1 or myPHP.php?param=2. No JavaScript is needed.
Why onclick="myPHP.php/'1'" does not work
An onclick attribute runs JavaScript. It does not tell the browser to execute a PHP file, and myPHP.php/'1' is not a valid JavaScript navigation or function call. PHP runs on the server, not in the browser. The browser must request a URL; the server then executes the PHP script and returns a response.
The slash is not query-string syntax. A URL parameter is normally written after a question mark, as in myPHP.php?param=1. A form is the simplest way to create that request from a button.
#1 Best Overall
Complete working example
Save this page as index.html and the PHP script as myPHP.php under a PHP-enabled web server. Open the page through an HTTP address such as http://localhost/, not by opening the HTML file directly with a file:// URL.
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Run PHP with a parameter</title>
</head>
<body>
<form action="myPHP.php" method="get">
<button type="submit" name="param" value="1">Run with 1</button>
<button type="submit" name="param" value="2">Run with 2</button>
</form>
</body>
</html>
The form’s action names the script that handles the submission. With method="get", form data is appended to the URL. Only the submit button that was clicked contributes its name=value pair, so the requests are myPHP.php?param=1 and myPHP.php?param=2. See the MDN form reference and MDN button reference.
myPHP.php
<?php
$param = $_GET['param'] ?? null;
if (!in_array($param, ['1', '2'], true)) {
http_response_code(400);
exit('Parameter must be 1 or 2');
}
echo 'You selected option ' . htmlspecialchars(
$param,
ENT_QUOTES,
'UTF-8'
);
$_GET is PHP’s associative array for query-string values. The null coalescing operator (??) supplies a fallback when param is missing, avoiding an undefined array key warning. The PHP manual documents $_GET and htmlspecialchars().
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →The strict allowlist accepts only the two values this page is meant to handle. A visitor can change the URL or construct a request by hand, so a value is not trustworthy merely because it came from a button. The strict third argument to in_array() prevents loose type comparisons.
Choose GET or POST based on what the script does
Use GET for a safe request that reads or displays information, such as selecting a view, filtering results, searching, or loading a record. GET data appears in the URL, so it is easy to bookmark and share; do not put secrets in it.
If clicking a button changes server-side state—such as deleting a record, updating an account, creating an order, or changing a setting—submit with POST instead:
<form action="myPHP.php" method="post">
<button type="submit" name="param" value="1">Perform action 1</button>
<button type="submit" name="param" value="2">Perform action 2</button>
</form>
<?php
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(405);
header('Allow: POST');
exit('POST required');
}
$param = $_POST['param'] ?? '';
if (!in_array($param, ['1', '2'], true)) {
http_response_code(400);
exit('Invalid parameter');
}
POST is not automatically secure or protected from cross-site request forgery (CSRF). State-changing actions still need appropriate authentication, authorization, validation, HTTPS, and CSRF defenses, such as a per-request token. See OWASP’s CSRF overview.
Other patterns
Use a link for read-only navigation
If the user is simply navigating to a read-only result, an anchor may be more appropriate than a button:
<a href="myPHP.php?param=1">Run with 1</a>
<a href="myPHP.php?param=2">Run with 2</a>
Use a form button to submit a form or trigger an action; use a link to navigate to a resource. Do not make a destructive operation happen through a GET link.
Send each button to a different PHP file
When two buttons share a form but need different endpoints, give each button a formaction:
<form method="get">
<button type="submit" formaction="first.php" name="param" value="1">
Run first script
</button>
<button type="submit" formaction="second.php" name="param" value="2">
Run second script
</button>
</form>
formaction overrides the form’s action for the button used to submit it. The button must still be associated with a form.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Use JavaScript only when you need client-side behavior
A normal form is sufficient for a page navigation. Use JavaScript and fetch() if the page must stay in place, update part of the screen, or exchange JSON with an endpoint. In that case, the buttons should usually be type="button", and the server must still validate the submitted value. JavaScript changes how the request is made; it does not replace server-side checks.
Best Value
Troubleshooting
- PHP source appears as text, or nothing runs: the page may be opened directly or served by a static-only server. Put the files under a PHP-enabled web server, visit them through HTTP, and check the server and PHP error logs.
$_GET['param']is missing: confirm the form usesmethod="get", its action points to the intended script, and the clicked submit button has bothname="param"and a value.- The button does not submit: make sure it is
type="submit"and belongs to the intended form. Atype="button"button does not submit a form, and a submit button without anamedoes not send that button’s value. - The script receives an unexpected value: use the same parameter name on both buttons and validate the received value against the choices the script supports.
Keep request values safe
Validate values against the application’s rules, then escape them for the output context. htmlspecialchars() is appropriate for HTML text or attributes when used correctly; it is not general-purpose input validation or escaping for JavaScript, SQL, shell commands, or filesystem paths.
Do not concatenate a request value directly into SQL, a filename, an include, a shell command, or a redirect target. For known actions, map external values to internal choices:
$actions = [
'1' => 'generate_report',
'2' => 'send_report',
];
$key = $_GET['param'] ?? '';
if (!isset($actions[$key])) {
http_response_code(400);
exit('Invalid parameter');
}
$action = $actions[$key];
As an application grows, descriptive values such as report or archive are easier to maintain than unexplained numbers. The server should still allowlist them and check whether the current user is authorized to perform the requested action.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

