我想通过单击按钮将 2 个 php 文件链接在一起


I want to link 2 php files together by clicking a button

我有 2 个 php 文件,我想通过单击按钮链接这两个文件.. 所以如果我单击第一个 php 文件中的按钮,它应该将我的传输到第二个 php 文件..

第一个php文件,在这里我想点击s&p数据库按钮:

<html>
<body>
<h1> My System </h1>
<form action="">
<input type="button" value="S & P Database ">
<input type="button" value="Generate Report  ">
</form>
</body>
</html>

单击按钮时我应该拥有的第二个 php 文件:

<html>
<body>
<form action="">
<h4><b>Please choose one of the following options below : </b> </h4>
<input type="radio" name="option" value="search" /> Search<br/>
<input type="radio" name="option" value="open database" /> Open Database<br/>
<input type="radio" name="option" value="administrative page "/> Administrative Page     <br/>
</form>
// This button doesn't appear in the web page =( .. dunno why 
<form action="">
<input type="button" value="Choose ">
</form>
</body>
</html>
如果我

理解正确,您希望在单击第一页上的按钮时将用户重定向到第二页。

要简单地重定向用户,您可以使用按钮的onclick

<input type="button" value="S & P Database" onclick="window.location.href='page2.php'" />
<input type="button" onClick="window.location='/2nd.php'" value="S & P Database ">​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

这会将您重定向到/2nd.php

你需要添加链接到php nahdler in action属性

所以它会<form action="http://www.website.com/1.php">

输入类型应为"图像"或"提交",按钮不会提交您的表单。

您也可以通过JS提交表单,但我不会在这里描述如何做到这一点。

使用正确的文档结构和文档类型:http://www.rantiev.com/doctypes/使用验证器检查您的代码:http://validator.w3.org/#validate_by_input当某些元素消失时,可能是HTML有错误。

有几种方法可以做到这一点:

2份表格提交到不同地点

<html>
<body>
<h1> My System </h1>
<form action="page2.php" method="get">
    <input type="button" name="pressed" value="S & P Database ">
</form>
<form action="page3.php" method="get">
    <input type="button" name="pressed" value="Generate Report  ">
</form>
</body>
</html>

2个指向不同位置的链接

<html>
<body>
<h1> My System </h1>
<a href="page2.php?pressed=sp">S & P Database</a>
<a href="page3.php?pressed=report">Generate Report</a>
</body>
</html>

1 个包含按钮名称和值的表单。但是您的脚本(page2.php)也需要检查 $_GET['按下'] 的值

<html>
<body>
<h1> My System </h1>
<form action="page2.php" method="get">
    <input type="button" name="pressed" value="S & P Database ">
    <input type="button" name="pressed" value="Generate Report  ">
</form>
</body>
</html>

但不要忘记urldecode($_GET['pressed'])),因为值将被编码。

简单的 put

方法="

发布"或方法="获取"

并在操作中键入第二个文件的名称,在您的情况下将是

action="2ndfile.php(不管它叫什么名字)"

也在 Cahnage 您的按钮提交

请记住,此操作脚本适用于您的第一个文件。