Jump to content

[SOLVED] Combining a word with a variable in a mysql query


cliftonbazaar

Recommended Posts

I can't seem to get this line of code working -

$sql = "UPDATE customers SET member'{$_SESSION['referrer']}'='1' WHERE userName='{$_SESSION['userName']}' ";

More specifically it's the

SET member'{$_SESSION['referrer']}'='1'

that I don't know how to do.

 

My database has memberships for different websites; so the fields are 'memberkoala', 'memberalien', 'memberdragon' e.t.c  I always need the work 'member' in there but I also need to add the variable $_SESSION['referrer'] to the filed name.

Link to comment
Share on other sites

I'm not sure exactly what you want but i think you are looking for CONCAT :

 

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat

 

But if you have many website in the same table why you don't add a column like that

 

website varchar(50)

 

AND

 

UPDATE customers SET referer='$_SESSION['referrer']', website='www.something.com' WHERE username='$_SESSION['userName']';

Link to comment
Share on other sites

Remove the single-quotes that are around '{$_SESSION['referrer']}' and if the fields are numeric, remove the single-quotes that are around the '1'

 

You can always echo your $sql variable after it has been assigned the query string to see what exactly is in it.

Link to comment
Share on other sites

Remove the single-quotes that are around '{$_SESSION['referrer']}' and if the fields are numeric, remove the single-quotes that are around the '1'

Brilliant, that did the trick  :)

 

You can always echo your $sql variable after it has been assigned the query string to see what exactly is in it.

 

This is one of things that I would never have thought about but once you read it you think "why the heck didn't I think of that before, it's so simple!"

 

Thanks for the replies.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.