colap Posted January 20, 2013 Share Posted January 20, 2013 $_SERVER['argv'][1'] = "$GGGabcd"; $query = "insert into table1 (str) VALUES(' " . $_SERVER['argv'][1] . " ')"; It's a string that starts with a dollar sign. So how can i insert this string into mysql table with php? How can i escape or something to add that string with $ (dollar) ? Quote Link to comment https://forums.phpfreaks.com/topic/273381-how-to-insert-string-with-dollar-sign-into-mysql-table/ Share on other sites More sharing options...
trq Posted January 20, 2013 Share Posted January 20, 2013 There is nothing special about a $ sign. Do you have an actual problem? Quote Link to comment https://forums.phpfreaks.com/topic/273381-how-to-insert-string-with-dollar-sign-into-mysql-table/#findComment-1407053 Share on other sites More sharing options...
DavidAM Posted January 20, 2013 Share Posted January 20, 2013 mySql does not treat the $-sign specially. However, if you happen to have a PHP variable named $GGGabcd (you should change the name to something meaningful), PHP will interpret the variable when you include it in a double-quoted string. Use single quotes: $_SERVER['argv']['1'] = '$GGGabcd'; Quote Link to comment https://forums.phpfreaks.com/topic/273381-how-to-insert-string-with-dollar-sign-into-mysql-table/#findComment-1407063 Share on other sites More sharing options...
salathe Posted January 20, 2013 Share Posted January 20, 2013 …if you happen to have a PHP variable named $GGGabcd… Variable interpolation will still occur regardless of whether the variable exists or not. php-coder, as DavidAM showed you should be using single-quotes around that string (or backslash-escaping the dollar). Quote Link to comment https://forums.phpfreaks.com/topic/273381-how-to-insert-string-with-dollar-sign-into-mysql-table/#findComment-1407079 Share on other sites More sharing options...
DavidAM Posted January 20, 2013 Share Posted January 20, 2013 @salathe: I did not realize that. I almost never use double-quoted strings. But I see you are correct, this code produces an "Undefined variable" notice. Yet another reason to avoid double-quoted strings. And to make sure error reporting is on during development. Quote Link to comment https://forums.phpfreaks.com/topic/273381-how-to-insert-string-with-dollar-sign-into-mysql-table/#findComment-1407081 Share on other sites More sharing options...
colap Posted January 21, 2013 Author Share Posted January 21, 2013 There is nothing special about a $ sign. Do you have an actual problem? PHP interprets the string starting with dollar sign as variable. So it doesn't insert that string into mysql table. Quote Link to comment https://forums.phpfreaks.com/topic/273381-how-to-insert-string-with-dollar-sign-into-mysql-table/#findComment-1407202 Share on other sites More sharing options...
trq Posted January 21, 2013 Share Posted January 21, 2013 yeah, I missed the fact that you had it within double quotes. Quote Link to comment https://forums.phpfreaks.com/topic/273381-how-to-insert-string-with-dollar-sign-into-mysql-table/#findComment-1407224 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.