Set comma after string write in mysql query in PHP

Posted on 2006-03-29
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!
Question by:stormist
    LVL 142

    Accepted Solution

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

    Expert Comment

    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 (.).
    LVL 10

    Author Comment

    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! :)

    LVL 10

    Author Comment

    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'";
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]

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

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Problem to echo 6 29
    undefined index setting cookie 11 29
    php explode 3 28
    Issues with signature 19 20
    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    The viewer will learn how to dynamically set the form action using jQuery.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now