使用 html 表单更新 mysql 数据库适用于杂货店 1,但不适用于杂货店 2


Updating mysql database using html form works for say grocerystore1 but not for grocerystore2

我有一个html表单,可以更新杂货店的usp,描述,区域等字段。当我选择任何杂货店来更新它时,数据库中已经存在的详细信息将被提取到 html 表单的文本区域,以便我可以在更新它之前看到已经存在的内容。

我举个例子:

假设这些是数据库中已有的两家杂货店的详细信息。

杂货店1:

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 表单更新这些字段时,它对 GROCERY STORE1 的更新非常好。但对于杂货店2,它不会更新。我发现的原因是杂货店2的字段中已经有太多的文字。然后我去了我的数据库,将GROCERY STORE2的详细信息编辑到最低限度,例如usp:好,描述:尼斯,地区,波士顿。现在当我使用 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");
}
?>

HTML 代码是

    <form name="myForm" action="" method="POST" action="condatabase.php" >
    <div>
    <label for="myname">USP*:</label>
    <textarea name="usp" id="box1" rows="5" cols="5"><?PHP echo $record12['usp']?>    
    </textarea>
    </div>
    <div>
    <label for="area_served">Areas served*:</label>
    <textarea name="area_served" id="box1" rows="5" cols="5"><?PHP echo    
    $record12['area_served']?></textarea>
    </div>
    <div> 
    <label for="email">description*:</label>
    <textarea name="description" id="box1" rows="5" cols="5"><?PHP echo    
    $record12['description']?></textarea>
    </div>
    <div id="thesubmit">
    <button class="button" input type="submit" name="submit" value="Comment"   
    />Submit</button>
    </div> <br>
    <div id="thesubmit">
    <button class="button" input type="reset" name="Reset" value="Reset" />Reset</button></div> 
    </form>

我没有看到你在哪里定义$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");

还要确保在文本中转义特殊字符

http://www.php.net/manual/en/mysqli.real-escape-string.php