我開始在PHP,我想知道如何顯示在HTML文件中的文本框中的MySQL數據。 我已經創建了兩個文件一個HTML和一個PHP,在調用數據到文本發送錯誤的那一刻。如何在文本框中顯示來自mysql的數據?
Error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in...
php文件
<?php
$server= "localhost";
$user = "root";
$password = "";
$bd = "test";
$conexion = mysql_connect($server,$user,$password) or die ("alert(error)");
mysql_select_db($bd,$conexion);
$query = mysql_query("SELECT city , zipcode FROM data WHERE client='$_POST[client]'");
while($rowvalor = mysql_fetch_array($query))
{
$city = $rowvalor['city'];
$code = $rowvalor['zipcode'];
}
mysql_close($conexion);
?>
HTML文件
<!DOCTYPE HTML>
<html>
<head>
<title>Test</title>
<body>
<form action = "test.php" method="post">
<button id="btnsearch" onclick="search()" style= "background: rgb(242, 243, 243); position: relative; left: 155px"; >Search</button>
<input id="txtclient" name="client" type="text" class="form-control" value= '<?php echo $client; ?>'/><span class="fa arrow"></span>
<input id="txtcode" name="zipcode" type="text" class="form-control" value= '<?php echo $zipcode; ?>'/><span class="fa arrow"></span>
<input id="txtcity" name="city" type="text" class="form-control" value= '<?php echo $city; ?>' /><span class="fa arrow"></span>
</form>
</body>
你應該使用「mysqli_select_db()」而不是「mysql_select_db()」嗎?最好與mysqli調用所有你的後續調用 –
我改變它爲「mysql_select_db」,但仍然是一個錯誤**「警告:mysql_fetch_array()期望參數1是資源,布爾在」** –