-1

I have an html form which updates fields like usp, description, area etc of grocery stores. When i choose any grocery store to update it, the details that are already there in the database are fetched to the text area of the html form so that I can see what is there already before I can update it.

Let me give an example:

suppose these are the details already in the database for the two grocery stores.

GROCERY STORE1:

usp: fresh
description:very good store
area: boston

GROCERY STORE2:

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

Now when i used the html form to update these fields, it updates perfectly fine for GROCERY STORE1. But for GROCERY STORE2 it doesnt update. The reason I found out was that there is already too much text in the fields of GROCERY STORE2 . Then I went to my database and edited the details for GROCERY STORE2 to a minimum, for example usp: good, description:nice, area,boston. Now when I use the html form to update it , it works fine. So whenever there is too much text already, this html form doesnt seem to work. How can I solve this. Thanks in advance

PHP code is

<?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 code is

    <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>
4

2 回答 2

0

我没有看到你在哪里定义$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");
于 2013-10-10T13:51:59.763 回答
-1

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

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

于 2013-10-10T08:20:32.150 回答