Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1886 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Updating MySQL help?

Thread title: Updating MySQL help?
Reply    
    Thread tools Search this thread Display Modes  
06-01-2009, 03:19 PM
#1
LongDogger is offline LongDogger
Status: Junior Member
Join date: Sep 2006
Location: Florida
Expertise:
Software:
 
Posts: 33
iTrader: 0 / 0%
 

LongDogger is on a distinguished road

Send a message via AIM to LongDogger Send a message via MSN to LongDogger

  Old  Updating MySQL help?

I'm having an odd trouble updating a table in MySQL. The PHP code I've written functions just fine, but the query is having an issue. It can update the columns 'msg' and 'title', but it refuses to update a column called 'desc'. Basically, I can create an entire new row perfectly fine, but I can only update two columns for whatever reason. Any help on this issue would be greatly appreciated.

This won't work:
Code:
mysql_connect(localhost, $username, $password) or die('Error: ' . mysql_error());
mysql_select_db($database) or die('Error: ' . mysql_error()); 
$query = "UPDATE msgs SET title='$title', desc='$desc', msg='$msg' WHERE msg_id=$msg_id";
$result = mysql_query($query) or die ('Error: ' . mysql_error());
mysql_close();
This will work:
Code:
mysql_connect(localhost, $username, $password) or die('Error: ' . mysql_error());
mysql_select_db($database) or die('Error: ' . mysql_error()); 
$query = "UPDATE msgs SET title='$title', msg='$msg' WHERE msg_id=$msg_id";
$result = mysql_query($query) or die ('Error: ' . mysql_error());
mysql_close();
The error message given is:

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc='ADADASDASD', msg='dfsdfsd' WHERE msg_id=14' at line 1

Reply With Quote
06-01-2009, 03:29 PM
#2
46Bit is offline 46Bit
Status: Member
Join date: Mar 2009
Location: Yorkshire
Expertise: Web Development
Software:
 
Posts: 275
iTrader: 10 / 100%
 

46Bit is on a distinguished road

Send a message via MSN to 46Bit Send a message via Skype™ to 46Bit

  Old

First of all, go into phpmyadmin and check that the field exists, is called desc, and is one of the (VAR)CHAR, TEXT, or BLOB types, with a length long enough for that string.

EDIT: Actually I've realised it's the use of the word 'desc' that's causing the problem. Put it in the weird quote character above the tab to get
Code:
UPDATE `msgs` SET `title` = '$title', `desc` = '$desc', `msg` = '$msg' WHERE `msg_id` = $msg_id

Reply With Quote
06-01-2009, 04:29 PM
#3
Salathe is offline Salathe
Salathe's Avatar
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
 
Posts: 3,820
iTrader: 25 / 100%
 

Salathe will become famous soon enough

Send a message via MSN to Salathe

  Old

DESC (case-insensitive) is a reserved word in MySQL which is used in ORDER BY clauses.

To use this as a column name in queries, as 46Bit mentioned, you have to use the weird quote character (`, the "identifier quote character" in MySQL, commonly "backtick" in programming, or "grave accent"). If the identifier (in this case a column name) is a reserved word (which desc is) then it must be wrapped in backticks (exception: if the column is referred to in table.column style).

Reply With Quote
06-01-2009, 09:46 PM
#4
LongDogger is offline LongDogger
Status: Junior Member
Join date: Sep 2006
Location: Florida
Expertise:
Software:
 
Posts: 33
iTrader: 0 / 0%
 

LongDogger is on a distinguished road

Send a message via AIM to LongDogger Send a message via MSN to LongDogger

  Old

Ha. Thanks goes out to both of you. I now know not to shorten description to desc. What luck I have...

Reply With Quote
Reply    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed