Php 使用html表单更新mysql数据库适用于grocerystore1,但不适用于grocerystore2
我有一个html表单,它可以更新杂货店的usp、描述、面积等字段。当我选择任何一家杂货店来更新它时,数据库中已经存在的详细信息会被提取到html表单的文本区域,这样我就可以在更新它之前看到已经存在的内容 让我举一个例子: 假设这是两家杂货店数据库中已有的详细信息 杂货店1:Php 使用html表单更新mysql数据库适用于grocerystore1,但不适用于grocerystore2,php,html,forms,Php,Html,Forms,我有一个html表单,它可以更新杂货店的usp、描述、面积等字段。当我选择任何一家杂货店来更新它时,数据库中已经存在的详细信息会被提取到html表单的文本区域,这样我就可以在更新它之前看到已经存在的内容 让我举一个例子: 假设这是两家杂货店数据库中已有的详细信息 杂货店1: usp: fresh description:very good store area: boston 杂货店2: usp:fresh products, nice store look, very good servic
usp: fresh
description:very good store
area: boston
杂货店2:
usp:fresh products, nice store look, very good service, customer friendly, bla bla bla...
description: located in one of the poshest places of the city this store is unique bla bla bla bla bla bla bla bla bla bla bla bla bla bla ..............
area: boston
现在,当我使用html表单更新这些字段时,它对杂货店1的更新非常好。但对于杂货店2,它不会更新。我发现的原因是在杂货店2的字段中已经有太多的文本。然后我转到数据库,将杂货店2的详细信息编辑到最低限度,例如usp:good,description:nice,area,boston。现在,当我使用html表单来更新它时,它工作得很好。因此,当已经有太多的文本时,这个html表单似乎不起作用。我怎样才能解决这个问题。提前谢谢
PHP代码是
<?php
if (!isset($_POST['usp']))
{
//If not isset -> set with dumy value
$_POST['usp'] = "";
}
if (!isset($_POST['area_served']))
{
//If not isset -> set with dumy value
$_POST['area_served'] = "";
}
if (!isset($_POST['description']))
{
//If not isset -> set with dumy value
$_POST['description'] = "";
}
if (!isset($_POST['submit']))
{
//If not isset -> set with dumy value
$_POST['submit'] = "";
}
$usp = $_POST['usp'];
$area_served = $_POST['area_served'];
$description = $_POST['description'];
$submit = $_POST['submit'];
if($submit)
{
$insert=mysql_query("UPDATE stores SET usp='$usp',area_served='$area_served',description='$description', WHERE store_id=$storeid");
header("Location:updateinfo.php?city_id=$cityid&store_id=$storeid");
}
?>
还要确保在文本中转义特殊字符
我看不出您在哪里定义$storeid
变量?可能是这样
此外,查询中的WHERE
前面还有一个额外的逗号。所以试试看
$insert=mysql_query("UPDATE stores SET usp='$usp',area_served='$area_served',description='$description' WHERE store_id=$storeid");
而不是
$insert=mysql_query("UPDATE stores SET usp='$usp',area_served='$area_served',description='$description', WHERE store_id=$storeid");
问题不在您的表单中,而是mysql\u查询的使用:1。转义输入2。不要使用mysql\u查询。请告诉我可以使用什么来代替mysql\u查询。还有一件事我想问的是,为什么它适用于一家商店而不适用于另一家。是不是在提交长文本之前超时了谢谢。。。但是我使用$get获取的storeid,然后将它传递给这个$storeid。查询工作正常。。。。但正如我所说的,如果文本越少,它就越有效,如果表单中输入的文本越多,它就不起作用。
$insert=mysql_query("UPDATE stores SET usp='$usp',area_served='$area_served',description='$description', WHERE store_id=$storeid");