数据库字段数据不出现在表单文本框在PHP


database field data not appearing in form textbox in PHP

我有这个代码在PHP和数据库sql..情况是……如果我输入1、2或3 (productID) ..将填充文本框并使用数据库值填充字段。但是当我运行程序时…幸运的是它没有错误…但是当我输入id或1并点击提交按钮。它没有得到必要的值。对不起,我是一个完全的新手,我练习PHP有一段时间了。任何帮助都可以。谢谢你. .

<?php
session_start();
include_once 'dbconnect.php';
if(!isset($_SESSION['user'])){
header("Location: index.php");
}
$res = mysql_query("SELECT * FROM users WHERE user_id=".$_SESSION['user']);
$userRow = mysql_fetch_array($res);
?>
<?php
require('dbconnect.php');
$id = (isset($_REQUEST['productID']));
$result = mysql_query("SELECT * FROM tblstore WHERE productID = '$id'");
$sql = mysql_fetch_array($result);
if(!$result){
die("Error: Data not found");
} else {
$brandname = $sql['brandname'];
$price = $sql['price'];
$stocks = $sql['stocks'];
}
?>
<html>
<body>
<p>
hi' <?php echo $userRow['username']; ?>&nbsp;<a href="logout.php?logout">Sign Out</a>
</p>
<form method="post">
<table align="center">
<tr>
<td>Search Apparel:</td>
<td><input type="text" name="search" name="productID" /></td>
</tr>
<tr>
<td>Brandname:</td>
<td><input type="text" name="brandname" value="<?php echo $brandname; ?>"/ </td>
</tr>
<tr>
<td>Price:</td>
<td><input type="text" name="price" value="<?php echo $price; ?>"/></td>
</tr>
<tr>
<td>Stocks:</td>
<td><input type="text" name="stocks" value="<?php echo $stocks; ?>"/></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="submit" value="Search" /></td>
</tr>
</table>
</form>
</body>
</html>

你得到的id不正确,你有:

<?php
$_REQUEST['productID']=8; //for testing
$id = (isset($_REQUEST['productID']));

如果你检查它,你会发现输出是true'false,由isset

返回
var_dump($id); //true

你应该使用的是:

<?php
if(isset($_REQUEST['productID'])){ //maybe also check its a number and or valid range
$id=$_REQUEST['productID'];
}