LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-01-2006, 09:11 AM   #1
thedude2010
LQ Newbie
 
Registered: Oct 2002
Posts: 12

Rep: Reputation: 0
bash variable loses contents in mysql statement


I have a variable $id that contains an id

I can echo it without any problem but...

as soon as I do this
`$mysql "insert into webusers_db(webuserid,db) values('"${id}"','"${db}"')"`

the db gets entered but the id is the default value in my table of zero
I have tried '$id' '"$id"' '"${id}"' '"[${id}]"' '"["${id}"]"' nothing seems to work
 
Old 06-01-2006, 10:11 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,290

Rep: Reputation: 174Reputation: 174
it's the single quotes, try this:

Code:
`$mysql "insert into webusers_db(webuserid,db) values(\'${id}\',\'${db}\')"`
 
Old 06-01-2006, 10:18 AM   #3
thedude2010
LQ Newbie
 
Registered: Oct 2002
Posts: 12

Original Poster
Rep: Reputation: 0
alright then...here what I got when I escaped the single 's
ERROR at line 1: Unknown command '\''.

/me scratches his head
 
Old 06-02-2006, 04:15 AM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
This should work:
Code:
$mysql "insert into webusers_db(webuserid,db) values('${id}','${db}')"
Quoting and escaping is not allways useful or needed
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BASH IF statement kinetik Programming 10 05-07-2006 02:48 AM
Bash: Print usage statement & exit; otherwise continue using Bash shorthand operators stefanlasiewski Programming 9 02-07-2006 05:20 PM
same system variable, but with different contents? kpachopoulos Linux - General 1 07-31-2005 05:15 PM
bash statement os2 Programming 2 03-20-2005 10:13 PM
get file contents with newlines into bash variable otoomet Linux - Software 2 01-06-2005 01:23 PM


All times are GMT -5. The time now is 08:38 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration