Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 03-23-2004, 08:34 AM   #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
adrianlewis is offline   Reply With Quote
Old 03-23-2004, 08:42 AM   #2
PCMech Founder
Staff
 
drisley's Avatar
 
Join Date: Mar 1999
Location: Tampa, FL
Posts: 1,950
Send a message via ICQ to drisley
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.
drisley is offline   Reply With Quote
Old 03-23-2004, 08:46 AM   #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
adrianlewis is offline   Reply With Quote
Old 03-23-2004, 09:07 AM   #4
Staff
Premium Member
 
mairving's Avatar
 
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.
mairving is offline   Reply With Quote
Old 03-23-2004, 09:11 AM   #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?
adrianlewis is offline   Reply With Quote
Old 03-23-2004, 09:20 AM   #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
adrianlewis is offline   Reply With Quote
Old 03-23-2004, 09:50 AM   #7
Staff
Premium Member
 
mairving's Avatar
 
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.
mairving is offline   Reply With Quote
Old 03-23-2004, 10:32 AM   #8
Professional gadfly
 
doctorgonzo's Avatar
 
Join Date: Jan 2002
Location: Minneapolis, MN
Posts: 6,364
Send a message via MSN to doctorgonzo
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).
doctorgonzo is offline   Reply With Quote
Old 03-24-2004, 04:37 AM   #9
aym
Registered User
 
aym's Avatar
 
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.
aym is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 12:50 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2