2013-02-07 18 views
1

我是PHP新手MySQL編程,我需要一個完整的示例php,mysqli和html腳本,它能夠通過多個文本框搜索表並返回結果。PHP MySQLi完成多個搜索示例文件

+0

[你嘗試過什麼?](http://whathaveyoutried.com) – Qix

+0

這是如何不關閉?... – Qix

回答

-1

首先將這些搜索值發佈到您的PHP代碼中。這可以使用HTML表單完成。

<form method="POST" action="script.php"> 
    <input name="name" type="text" /> 
    <input name="phone" type="text" /> 
    <input type="submit" value="Search" /> 
</form> 

之後您需要在PHP腳本中訪問這些值。

// Sql.php

<?php 


$server = 'localhost'; 
$user = 'root'; 
$password = ''; 
$database = 'test'; 

$connection = new mysqli($server, $user, $password, $database); 
if (mysqli_connect_errno()) { 
    die("<p><font color='red'>Errrrrror!</font>"); 
} 

$name = mysql_real_escape_string($_POST['name']); 
$phone = mysql_real_escape_string($_POST['phone']); 

$sql = "SELECT * FROM `table` WHERE (
    `name` = '{$name}' AND 
    `phone` = '{$phone}' 
)"; 
$result = $connection->query ($connection, $sql) 
     OR die("Eeeek! Query failed."); 

$connection-> close; 
?> 
+1

嗨維沙爾,太謝謝你了。我需要這樣的開始。保持良好。約瑟夫 – user1868306