Question:

PHP MySQL UPDATE TEXT problem

by  |  earlier

0 LIKES UnLike

I am try to update a table, but it dose not work. The desc field caused the error (it is a of type TEXT). It works if I remove the line that updates one field called "desc". I had a problem inserting, but when I used mysql_escape_string() function the data it worked. But, I do that and it still cause an error. Bellow is the code:

$address = $_POST['address'];

$city = $_POST['city'];

$pc = $_POST['pc'];

$province = $_POST['province'];

$desc = mysql_escape_string($_POST['desc']);

$propertytype = $_POST['propertytype'];

$buildingtype = $_POST['buildingtype'];

$years = $_POST['years'];

$contact = $_POST['contact'];

$foundationType = "";

for($i = 0; $i < count($_POST['foundationType']);$i )

$foundationType .= $_POST['foundationType'][$i]." ";

$con = msqlDBConnect();

if(!$con) {

return "ERROR 3: Database error could not edit account. Please try again";

}

mysql_select_db("dryb4554_projects",$con...

$sql = "UPDATE projects_1 SET ";

$sql .= "address='$address', ";

$sql .= "city='$city', ";

$sql .= "pc='$pc', ";

$sql .= "province='$province', ";

$sql .= "desc='$dsc', ";

$sql .= "propertytype='$propertytype', ";

$sql .= "buldingtype='$buildingtype', ";

$sql .= "buildingage='$years', ";

$sql .= "foundationtype='$foundationType', ";

$sql .= "contact='$contact' ";

$sql .= "WHERE id=".$_GET['id'];

if(!mysql_query($sql,$con))

{

mysql_close($con);

return "ERROR 4: Database Error. Unable to update info. please try again.<BR>";

}

I have done everthing I think of. I have checked to make sure that the name is correct. Even if I just right a word in like 'hello' it still dose ont work. If I remove the one line it works, but with the line that adds the desc to sql string is added it query fails. Is there something I don not know about TEXT type???

 Tags:

   Report

1 ANSWERS


  1. desc is a reserved word in MySQL -- if you have a command line, try typing &quot;desc your_table_name&quot; to see what I mean.

    Try changing that line to:

    $sql .= &quot;`desc`=&#039;$dsc&#039;, &quot;;

    (those things around desc are the little backwards single quote thingy somewhere up on the top row of your keyboard -- I&#039;m sure it has a more proper name, but I don&#039;t know what it is).

    The other option (and what I would do if at  all possible) is to change the name of that column.  I inherited a couple of tables with reserved words as column names in a big project, and I wish I&#039;d changed them months ago, because it is such a nuisance to remember to delimit them (and I waste a lot of time figuring out the problem when I forget).

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.