?
Solved

Set comma after string write in mysql query in PHP

Posted on 2006-03-29
5
Medium Priority
?
506 Views
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!
0
Comment
Question by:stormist
  • 2
  • 2
5 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 16330032
$sql = "UPDATE user SET session_requests='$usernumber,' WHERE username ='$un'";
0
 
LVL 2

Expert Comment

by:JoshdanG
ID: 16330071
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 (.).
0
 
LVL 10

Author Comment

by:stormist
ID: 16330073
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! :)



0
 
LVL 10

Author Comment

by:stormist
ID: 16330086
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'";
???
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16330109

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

615 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