以下代碼完美地起作用。它給人的預訂ID RRGPGM68
如何使用mySql唯一ID /列名稱搜索記錄?
<?PHP
$con=mysqli_connect("localhost","username","pasword","dbName");
// Check connection
if (mysqli_connect_errno()) {
die ("Failed to connect to MySQL: " . mysqli_connect_error());
}
$booking_id_serch_text = RRGPGM68;
$searchroute = "select * from booking_tbl where booking_nmbr = '$booking_id_serch_text'";
$result = $con->query($searchroute);
$row = $result->fetch_assoc();
echo 'Hotel URL: '.$row['hotel_url'];
mysqli_close($con);
?>
的hotel url
但我想從一個文本輸入域動態分配的booking_id_serch_text
。所以我改變了代碼如下:
<form action="<?php echo get_permalink();?>" method="post">
<input type="text" placeholder="Search..." required name="search_text">
<input type="button" value="search" name="search">
</form>
<?PHP
if($_POST["search"]){
$serch_text = $_POST["search_text"];
$con=mysqli_connect("localhost","username","pasword","dbName");
// Check connection
if (mysqli_connect_errno()) {
die ("Failed to connect to MySQL: " . mysqli_connect_error());
}
$booking_id_serch_text = $serch_text;
$searchroute = "select * from booking_tbl where booking_nmbr = '$booking_id_serch_text'";
$result = $con->query($searchroute);
$row = $result->fetch_assoc();
echo 'Hotel URL: '.$row['hotel_url'];
mysqli_close($con);
}
?>
但上面的代碼只是什麼都沒做。 我該如何使它工作? 我將在此目的歸檔後添加驗證。
這是一個有價值的解釋..謝謝你.. – 2014-09-19 08:42:23