There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
black screen blue screen boot computer connection crash css dell display driver drivers error excel firefox firefox 3 game hard drive internet internet explorer itunes laptop lcd linux malware monitor network networking nvidia outlook outlook 2003 outlook express partition password printer problem problems ram router slow software sound sprtcmd.exe trojan usb video virus vista windows windows xp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
MySQL Using 'Update' Command


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
malcolmd3111's Avatar
Member with 53 posts.
 
Join Date: Aug 2005
Experience: Intermediate
19-Dec-2005, 12:57 PM #1
Question MySQL Using 'Update' Command
I need to modify some records in a MySQL table. The defined field contains text. My syntax (in Perl) is as follows:

$statement = "UPDATE tblgenjnl SET printview='$prv_row' WHERE record='$row[0]' ";

tblgenjnl is the Table
printview is the field to be updated
$prv_row is the new content
record is the record number
$row[0] is the retrieved value from the table of required record.

The program runs, but there is something wrong with this command syntax. Any help woould be appreciated.

Thanks,

Malcolm3111
RGregory's Avatar
Member with 67 posts.
 
Join Date: Jul 2005
Experience: Advanced
19-Dec-2005, 04:40 PM #2
Not familiar with Perl, but if record is a variable, shouldn't it be outside of the quotes as in...

$statement = "UPDATE tblgenjnl SET printview='$prv_row' WHERE '#record'='$row[0]' ";
cristobal03's Avatar
Distinguished Member with 2,992 posts.
 
Join Date: Aug 2005
Experience: Advanced
19-Dec-2005, 05:11 PM #3
That shouldn't be a problem with perl, which interpolates variables in strings (that was my first instinct as well, but I'm pretty confident that isn't the issue).

Saying "there is something wrong with this command syntax" is somewhat ambiguous. Is the code generating errors? Is there an unacceptable pattern to the queries? Can't you print a log of the strings to see what's actually being sent to the MySql engine?

I guess I mean, what behavior are you seeing to suggest it's problem code?

chris.
cristobal03's Avatar
Distinguished Member with 2,992 posts.
 
Join Date: Aug 2005
Experience: Advanced
19-Dec-2005, 05:14 PM #4
[bump]

Though, actually, now, let's see...it's been a while since I've used perl...RGregory may have it.

I believe it is the single quotes that are causing the trouble. Single quotes in perl indicate literal strings, I believe, so those variables $prv_row and $row[0] are not being interpolated into the string.

You might have to use ASCII/ANSI character functions to generate the single-quotes. Or escape them using a backslash (I think that's perl's escape character, anyway).

HTH

chris.
malcolmd3111's Avatar
Member with 53 posts.
 
Join Date: Aug 2005
Experience: Intermediate
20-Dec-2005, 09:38 AM #5
Thanks for the replies. I evaluated my sql expression again and found the problem. The correct syntax is shown below:

'UPDATE tblgenjnl SET printview="$prv_row" WHERE record="$row[0]"')

Unlike Perl which uses "" to evaluate an expression, rather than ' ' (single quotes) MySQL requires the double quotes to stop a var being evaluated. In the statement above the variable $prv_row is free form text containing MySQL reserved words. Using single quotes the MySQL parser evaluates the contents, with double quotes it does not.

This all began because of the incompatibilities between FileMakerPro and MySQL regarding new line chars.

Peace
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 08:35 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.