We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


Set comma after string write in mysql query in PHP

stormist asked
Medium Priority
Last Modified: 2012-05-05
This is driving me nuts, I thought i had it but guess not.. I am simply trying to add a comma after the string write in this query:
 $sql = "UPDATE user SET session_requests='$usernumber' WHERE username ='$un'";

What is the proper way to add a comma to session_requests so that say the usernumber is 5 it will read "5,"

I've tried filling a variable with comma like
$comma = ',';

then doing this
$sql = "UPDATE user SET session_requests='$usernumber'.$comma WHERE username ='$un'";
but that doesn't work

Tried it about 4 other ways too. If you can help me out can you show me the ways to do this by:
1) assigning a comma to a variable
2) doing it without a variable like
$sql = "UPDATE user SET session_requests='$usernumber'.',' WHERE username ='$un'";
or whatever works..

Thanks a bunch!
Watch Question

Billing Engineer
Most Valuable Expert 2014
Top Expert 2009
$sql = "UPDATE user SET session_requests='$usernumber,' WHERE username ='$un'";

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

The main problem you are having is that you are putting the dot/concatenation operator (.) into your SQL statement, but that's the PHP syntax.  angelIII has given you the best solution and deserves all the points, but if for some crazy reason you did want to do the concatenation on the SQL side it would be:

$sql = "UPDATE user SET session_requests='$usernumber'+',' WHERE username ='$un'";

The only change being that you use a plus (+) instead of a dot (.).


Ok wow that was easy. Works now. AngelIII how would I do it if I wanted to put the comma in a variable? Oh and Thanks! :)


Thanks for the comments JoshdanG, I understand. Any idea how to put two variables next to each other?? use '+' as well? like
$sql = "UPDATE user SET session_requests='$usernumber'+'$comma'' WHERE username ='$un'";
Guy Hengel [angelIII / a3]Billing Engineer
Most Valuable Expert 2014
Top Expert 2009


$sql = "UPDATE user SET session_requests='$usernumber$comma' WHERE username ='$un'";
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.