gpt4 book ai didi

php - 如何使用 MySQL 数据填充 php/html 表单

转载 作者:太空宇宙 更新时间:2023-11-03 10:58:50 25 4
gpt4 key购买 nike

我正在尝试创建一个程序,用户可以在其中更新任何特定产品。当用户单击 UPDATE 按钮时,将打开一个表单。我想用 MySQL 数据填充 HTML 表单。我已经编写了以下代码,但它给了我一条错误消息。我只共享代码的 HTML 部分。我在 PHP echo 中使用这个 FORM。请检查一下。

HTML:

<label>Product Name:</label>  
</td>
<td>
<input type='text' name='product_name' value='<?php echo $fetch['product_id']; ?'/>*Required
</td>
</tr>

错误信息:

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE),
expecting identifier (T_STRING) or variable (T_VARIABLE) or number
(T_NUM_STRING) in F:\xampp\htdocs\CMS\update_single_product.php

完整代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>

<?php

include 'connect.php';
$id= $_GET['product_id'];

$select_query= "select * from products Left join product_description
ON products.product_id=$id and product_description.product_id=$id";

if(!$select_query_run= mysql_query($select_query))
{
echo mysql_error();

}

else
{
$fetch = mysql_fetch_array ($select_query_run);



echo "
<form action='insert_product.php' method='POST' enctype='multipart/form-data' >
<table border=1>
<tr>
<td>

<label>Product Name:</label> </td> <td><input type='text'
name='product_name' value='<?php echo $fetch['product_id']; ?>' />*Required</td></tr>

<tr><td><label>Item No:</label></td> <td><input type='text' name='item_no' ></td></tr>


<tr><td> Image3:</td><td> <input type='file' name= 'image3' ></td></tr></table> ";


/*------------------
Drop Down List Start
------------------ */


echo "<select name='category'>";

$select_query= 'Select * from category';
$select_query_run = mysql_query($select_query);

$sub_category_query= "Select * from sub_categories";
$sub_query_run= mysql_query($sub_category_query);



while ($select_query_array= mysql_fetch_array($select_query_run) )
{

echo "<option value='".$select_query_array['category_id']."' >".
htmlspecialchars($select_query_array["name"]).

"<option value='".$sub_query_run['sub_category_id']."' >" .
htmlspecialchars($sub_query_run['sub_category_name']). "</option>".

"</option>";




}
echo "</br>";

$selectTag= "</br><input type='submit' value='Update Product' /></select></form>";

echo "</div></div>";

echo $selectTag;

谢谢

最佳答案

$id=    $_GET['product_id'];
$select_query= "select * from products Left join product_description
ON products.product_id=$id and product_description.product_id=$id";

请注意,您可能在这里构建了一个 sql 注入(inject)。请阅读以下链接如何防止它们。 How can I prevent SQL injection in PHP?

关于php - 如何使用 MySQL 数据填充 php/html 表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17802854/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com