我想从数据库中回应出描述。 但是,当我查看它时,它无法加载。 我想知道为什么,是因为html采用textarea格式,因此它无法回应出来? 因为当我回应其他变量时,它可以回声。那些是文本字段格式
这是我的代码
php code
<?php
session_start();
if(!isset($_SESSION["manager"])){
header("location: admin_login.php");
exit();
}
//check that manager session is in database
$managerID = preg_replace('#[^0-9]#i','',$_SESSION["id"]);
$manager = preg_replace('#[^A_Za-z0-9]#i','',$_SESSION["manager"]);
$password = preg_replace('#[^A_Za-z0-9]#i','',$_SESSION["password"]);
$sql = mysql_query("SELECT * FROM admin WHERE id = '$managerID' AND username='$manager' AND password = '$password' LIMIT 1");
//make sure person exist in database
$existCount = mysql_num_rows($sql);
if($existCount == 0) {
echo " Your login session data is not on record in the database";
exit();
}
?>
<?php
if(isset($_POST['description'])){
$pid = mysql_real_escape_string($_POST['thisID']);
$product_name = mysql_real_escape_string($_POST['product_name']);
$product_price = mysql_real_escape_string($_POST['product_price']);
$category = mysql_real_escape_string($_POST['category']);
$subcategory = mysql_real_escape_string($_POST['subcategory']);
$product_description = mysql_real_escape_string($_POST['description']);
$product_package = mysql_real_escape_string($_POST['product_package']);
$sql = mysql_query("UPDATE supermarket SET category='$category', subcategory='$category',name='$product_name', description='$product_description',packaging='$product_package', price='$product_price' WHERE id='$pid'");
if($_FILES['fileField']['tmp_name'] != "") {
//place image in the folder
$newname = "$product_description.jpg";
//place image in the folder
move_uploaded_file($_FILES['fileField']['tmp_name'],"images/$newname");
}
header("location: inventorylist.php");
exit();
}
?>
<?php
//gather this product full info
if(isset($_GET['pid'])){
$targetID = $_GET['pid'];
$sql = mysql_query("SELECT * FROM supermarket WHERE id = '$targetID' LIMIT 1");
$productCount = mysql_num_rows($sql);//count output amount
if($productCount > 0){
while($row = mysql_fetch_array($sql)){
$id = $row['id'];
$product_description = $row["description"];
$product_name = $row["name"];
$category = $row["category"];
$subcategory = $row["subcategory"];
$product_price = $row["price"];
$product_package = $row["packaging"];
}
}
else{
$product_list = "Sorry, it don't exist";
exit();
}
}
?>
php的HTML代码
<textarea name="description" id="description" value="<?php echo $product_description ?>" cols="64" rows="5"></textarea>
答案 0 :(得分:0)
textarea
没有value
属性。
它应该是:<textarea><?=$var?></textarea>
答案 1 :(得分:0)
试试这个
<textarea name="description" id="description" cols="64" rows="5"><?php echo $product_description ?></textarea>