0
你好返回的結果從數據庫中,我做了這個簡單的代碼來顯示從我的數據庫信息到一個表,表單代碼如下: http://pastebin.com/yyzcjshn我如何能展現在提交表單的同一頁上使用PHP
的show.php代碼:
<html>
<head>
<title>Show Result</title>
<?php
$connection = mysql_connect("localhost","root","");
// Check connection
if(!$connection){
die("Database connection failed: " . mysql_error());
}
//select database to use
$db_select = mysql_select_db("sells",$connection);
if(!$db_select){
die("Database selection failed: " . mysql_error());
}
$D1 = $_POST['D1'];
//show info
if($D1 != 'Show All'){
$result = mysql_query("SELECT * FROM clients WHERE Status='$D1'", $connection);
}
else $result = mysql_query("SELECT * FROM clients", $connection);
if(!$result){
die("Database query failed: " . mysql_error());
}
echo "<table border='1'>
<tr>
<th>Order ID</th>
<th>Client Name</th>
<th>URL</th>
<th>Quantity</th>
<th>Price[$]</th>
<th>Status</th>
</tr>";
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row["Order_ID"]."</td>";
echo "<td>" . $row["ClientName"]."</td>";
echo "<td><a href=" . $row['Url'] . " target=_blank >" . $row['Url'] . "</a></td>";
echo "<td>" . $row["Quantity"]."</td>";
echo "<td>" . $row["Price"]."</td>";
echo "<td>" . $row["Status"]."</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($connection);
?>
</head>
</html>
我怎樣才能顯示結果中使用PHP提交表單(沒有Ajax)的同一頁?
你對「同一頁」的定義是什麼?你的意思是沒有刷新瀏覽器/按下提交按鈕時導航到新頁面? – EWit 2014-09-13 10:24:04
是的,我不希望它在另一個頁面中顯示結果。 – WhiteOne 2014-09-13 10:26:47
你的代碼易受[注入](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php?rq=1)和'mysql_ *'函數[棄用](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php/12860046#12860046)。 – 2014-09-13 10:31:58