2016-01-23 77 views
2

我想要去按其他PHP网页按下同一网站的HTML按钮。我已经通过使用标题功能来尝试它,但它不起作用。
下面是简单的html代码:PHP:如何更改按下html按钮的PHP页面的url?

<input type="button" name="Insert_Ad" value="Post and ad"> 

如果用户点击该按钮将它带到另一个PHP页面对于URL地址经过“HTTP实例://localhost/Product.php/Product。 PHP的”

这里是一个PHP页面的代码,而我想去按下按钮

<html> 
    <head> 
     <meta charset="UTF-8"> 
     <title>Insert form data</title> 
    </head> 
    <body> 
    <form method="post" action ="Product.php" id="contact-form"> 

     <input type="text" name="product_category" placeholder="product_category" required /> 



     <input type="text" name="product_name" placeholder="product_name" required /> 

     <textarea id = "address" name="product_description" placeholder="product_description" required /></textarea> 


     <input type="text" name="product_image1" placeholder="product_image1" required /> 


     <input type="text" name="product_image2" placeholder="product_image2" required /> 

     <input type="text" name="product_image3" placeholder="product_image3" required /> 

     <input type="text" name="product_image4" placeholder="product_image4" required /> 

     <input type="text" name="product_image5" placeholder="product_image5" required /> 


     <div class="btn-group" role="group"> 
      <input type="submit" class="btn btn-default" name="Add" value="Enter the box" style="margin-top: 15px; margin-right: 15px; border-radius: 4px;"> 

     </div> 

    </form> 

    <?php 
$servername = "localhost"; 
$username = "root"; 
$password = "zz224466"; 
$dbname = "zain"; 

// Create connection 
$conn = new mysqli($servername, $username, $password, $dbname); 
// Check connection 
if ($conn->connect_error) { 
    die("Connection failed: " . $conn->connect_error); 
} 

if(isset($_POST['Add'])) 
{ 
    $product_category = $_POST['product_category']; 
    $product_name = ($_POST['product_name']); 
    $product_description = ($_POST['product_description']); 
    $product_image1 = ($_POST['product_image1']); 
    $product_image2 = ($_POST['product_image2']); 
    $product_image3 = ($_POST['product_image3']); 
    $product_image4 = ($_POST['product_image4']); 
    $product_image5 = ($_POST['product_image5']); 


    $sql = "INSERT INTO zain.product (product_category,product_name,product_description,product_image1,product_image2,product_image3,product_image4,product_image5) 
VALUES ('$product_category','$product_name','$product_description','$product_image1','$product_image2','$product_image3','$product_image4','$product_image5')"; 
mysqli_query($conn,$sql); 
    if (mysqli_query($conn,$sql)) 
    { 
     echo "New record created successfully"; 
    } 
    else 
    { 
     echo "Error: " . $sql . "<br>" . $conn->error; 
    } 
    $conn->close(); 
} 
?> 


    </body> 
    </html> 

请帮助我该怎么做

+0

你到底要 –

+0

在按HTML按钮,我希望它会采取用户PHP页面 –

+0

我想,你正在寻找的是阿贾克斯https://developer.mozilla.org/en-US/docs/AJAX/Getting_Started。或者你只是想要一个链接,看起来像一个按钮? ... PHP是唯一的服务器端,clientside其html和js,所以你可以使用链接去另一个url或者你可以通过ajax加载新内容 –

回答

1

这是最简单的方法:
<input type="button" name="Insert_Ad" value="Post and ad" onclick="location.href='your_url_here'">

或者你可以使用一个表格提交给定的URL:
<form action="your_url_here"> <input type="submit" name="Insert_Ad" value="Post and ad"> </form>

+0

它正在工作,但它显示两个HTML按钮? –

+0

好吧,这是我的错误..我发现它工作...非常感谢Thankyou –

1

我会建议使用锚标签。如果你想给它一个按钮的外观,那么使用CSS将其设置为一个按钮。举例来说,如果你使用Twitter bootstrap,这将涉及到给它一类的BTN

<a href="/Product.php" class='btn'>Post an ad</a> 

如果你坚持要用一个按钮,那么你可能想将其套在一个HTML表单,其中动作属性指向您要导航到的页面。该方法必须是GET。如果它是表单中的唯一按钮,那么即使没有type =“submit”属性,它也将默认为提交按钮。

<form action="/Product.php" method="GET"> 
    <input type="button" name="Insert_Ad" value="Post and ad"> 
</form>