LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
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: Debian
Posts: 2,536

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


Reply



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:07 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration