简体   繁体   English

如何将 PHP 文件链接到 html 按钮

[英]How to link a PHP file to a html button

I want to load a php file when the user clicks on the button, but it isn't working and php file is not loaded.我想在用户单击按钮时加载一个 php 文件,但它不起作用并且未加载 php 文件。 Is there any way to link the php file to the button via anchor tag?有没有办法通过锚标记将php文件链接到按钮?

<a href="visual.php" > <button name="visual" id="newbtn" >Add Visual device</button></a> <a href="audio.php" ><button name="audio" id="newbtn" >Add Audio device</button></a> <a href="visual.php" > <button name="visual" id="newbtn" >Add Visual device</button></a> <a href="audio.php" ><button name="audio" id="newbtn" >Add Audio device</button></a>

I need to create a main html page which includes only two buttons and when "Add Visual device" button is clicked a php page is loaded with a form to add details about the device to visual device table in sql database.我需要创建一个仅包含两个按钮的主 html 页面,当单击“添加可视设备”按钮时,一个 php 页面将加载一个表单,以将有关设备的详细信息添加到 sql 数据库中的可视设备表中。 When the "Add Audio device" button is clicked it need to load the php page with form to send the data to the audio table in the db.当单击“添加音频设备”按钮时,它需要加载带有表单的 php 页面以将数据发送到数据库中的音频表。 But nothing loads when the buttons are clicked... I want to load the two pages when the respective buttons are clicked但是单击按钮时没有加载任何内容...我想在单击相应的按钮时加载两个页面

here is the code to hit php file through anchor tag.这是通过锚标记命中php文件的代码。

 <html> <body> <a href="audio.php">visit php file</a> </body> </html>

here is the code to hit php file through button.这是通过按钮点击php文件的代码。

 <form action="audio.php" method="get"> <input type="text" name="id"> <input type="submit" value="Open Form"> </form>

you can do it by adding onclick event as follows您可以通过添加onclick事件来做到这一点,如下所示

<button onclick="window.location.href = 'audio.php';">Add Audio device</button>
<button onclick="window.location.href = 'visual.php';">Add Visual device</button>

//It can be useful when you are not using a <form> tag.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM