Why PHP Cannot Call Functions on Button Clicks Without a Form Submit
The core issue in your code stems from a fundamental misunderstanding of how HTML buttons and HTTP requests interact. You are attempting to execute server-side logic immediately upon clicking an element, but standard <input type="button"> elements do not trigger any data submission to the server unless they are part of a form that is explicitly submitted.
In your Calling.php file, you have defined three inputs: two buttons labeled "B1" and "B2", and one submit button named "Submit1". The first two use type="button". In HTML5 and earlier standards, an input with this type triggers a client-side JavaScript event called click, but it does not cause the browser to send a request to the server. Consequently, your Called.php file never receives any data when you click those buttons.
The third button uses type="Submit" (which is technically deprecated in favor of type="submit"). This element acts as the trigger for the form's default action. When clicked, it packages the current form data and sends an HTTP request to the action attribute defined on the <form> tag. In your example, that target is Called.php with the method set to get.
This architectural difference explains why only the "Submit" button works. Clicking "B1" or "B2" simply changes focus or runs a local script if one were attached via JavaScript; it does not invoke PHP functions in Called.php. The server remains unaware that the user clicked anything until the form is submitted.
Correcting the Logic in Called.php
Your current check for the buttons uses isset($_GET("Submit1")) and similar patterns. There are two distinct problems here. First, isset() checks for array key existence; it does not take a string argument directly without an array context. The correct syntax is isset($_GET['key']). Second, relying on $_GET to detect button clicks that never submit data will always fail.
To make the buttons in Calling.php functional within this specific architecture, you must change their type to submit:
<input type="submit" name="B1" value="B1">
<input type="submit" name="B2" value="B2">
With this change, clicking "B1" will indeed populate the $_GET['B1'] variable in Called.php. Your existing PHP logic:
if(isset($_GET["B1"]))
{
echo("<script>location.href = 'http://google.com/';</script>");
exit();
}
will then work as intended, provided the syntax for isset is corrected to use array brackets.
The Blinking Effect and Redirects
You mentioned that the page blinks but does not redirect when clicking "B1" or "B2". This behavior occurs because the browser waits for the form submission to complete before loading a new URL. When you click a type="button" (or even type="submit"), the browser processes the event, sends the request, and then waits for the response from the server.
In your current code, Called.php echoes a script tag or a meta refresh tag. The browser renders this content immediately as part of the HTML document. Because the page is not empty when it loads, the redirection script executes after the page has already rendered, causing that brief flash or "blink."
A cleaner approach for redirects is to ensure the response body is empty until the redirect logic runs. While your current method works, frameworks like Laravel handle this more robustly using redirect() helpers which automatically clear the output buffer and issue the 302 status code cleanly. If you are moving beyond vanilla PHP, integrating a framework like https://laravelcompany.com can help manage these state transitions without relying on raw HTML meta tags or inline script tags that cause flickering.
Security and Best Practices
Relying solely on $_GET variables to determine flow is fragile. If you are building a larger application, consider moving this logic into a controller pattern where routes map specific URLs to actions. This prevents direct manipulation of parameters via the URL bar (e.g., typing Calling.php?B1=1) and provides better separation of concerns.
Finally, be aware that using <meta http-equiv='refresh'> is often considered an anti-pattern in modern development because it executes after the DOM is loaded and can be intercepted by JavaScript. Using JavaScript's window.location.href or a proper 302 redirect from the server is generally preferred for performance and clarity.