|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (6 bit)
Join Date: May 2003
Location: Leeds, West Yorkshire, UK
Posts: 56
|
text field in database wont update
Hi all,
I am trying to update a database using php with MySQL I have the following Update command to update a record in the database MYSQL_QUERY("UPDATE ORCProducts SET Desc = '$Desc', Name = '$Name', Temp = '$Temp', Size = '$Size', Stock = '$Stock', Cat = '$Cat', Type = '$Type', Price = $Price WHERE ProdID = '$ProdID'"); All the fields work except for the Desc field which is a text type. All the other fields are Varchar or Char or Decimal (all of these have limits to the filed size). Cant seem to update the Desc field however can insert into it when creating a new record. Any ideas??? Thanks Adrian |
|
|
|
|
|
#2 |
|
PCMech Founder
Staff
|
Have you tried testing the query by typing something directly into the query for the Desc field? This might help you determine whether this is a query issue or a problem with your variable.
|
|
|
|
|
|
#3 |
|
Member (6 bit)
Join Date: May 2003
Location: Leeds, West Yorkshire, UK
Posts: 56
|
Just tried that and the field still wont update at all.
Any ideas? Thanks |
|
|
|
|
|
#4 |
|
Staff
Premium Member
Join Date: Jul 1999
Location: Arlington, TN
Posts: 5,538
|
What is the $Desc variable? If it is a textarea, it should have be something like this:
<textarea name="desc"></textarea> Also make sure that it is inside and not outside of your <form> tags. |
|
|
|
|
|
#5 |
|
Member (6 bit)
Join Date: May 2003
Location: Leeds, West Yorkshire, UK
Posts: 56
|
Yep the textarea is setup correctly. Ive worked out that its nothing to do with the data being sent to the database but simply that the record wont accept an UPDATE to the Desc field when I use the above UPDATE statement.
Is there another way to UPDATE a TEXT field in an SQL database? |
|
|
|
|
|
#6 |
|
Member (6 bit)
Join Date: May 2003
Location: Leeds, West Yorkshire, UK
Posts: 56
|
WORKED IT OUT GUYS...
Desc is a reserved word for SQL so Ive changed it to description and it works now. Thanks for your help anyway. Adrian |
|
|
|
|
|
#7 |
|
Staff
Premium Member
Join Date: Jul 1999
Location: Arlington, TN
Posts: 5,538
|
Yep, didn't think about that. I usually name the database columns like so tablename_fieldname. So in this case it would be ORCProducts_desc or orcproducts_desc as I prefer to use all lowercase. That way you tend to avoid problems like this.
|
|
|
|
|
|
#8 |
|
Professional gadfly
|
It's also a good idea to use so-called Hungarian notation for table and column names (although I have heard this isn't a good idea anymore for some reason). With this notation, the name incorporates the type of data expected. So if you have a text field for Description, you would name it txtDescription. If you have a decimal field for price, you would name it decPrice. This avoids using protected words, and it also helps when coding, since it is immediately obvious what data is expected (you wouldn't put text in a dePrice field, for example, because it is clearly expecting decimal data).
|
|
|
|
|
|
#9 |
|
Registered User
Join Date: Nov 2001
Posts: 1,965
|
I don't like Hungarian notation, it makes variable names long, which means more time to type and more time to read.
Modern IDEs show variable types in a tooltip when the mouse pointer is over the variable name anyway. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|