cliftonbazaar Posted April 11, 2009 Share Posted April 11, 2009 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 https://forums.phpfreaks.com/topic/153683-solved-combining-a-word-with-a-variable-in-a-mysql-query/ Share on other sites More sharing options...
gffg4574fghsDSGDGKJYM Posted April 12, 2009 Share Posted April 12, 2009 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 https://forums.phpfreaks.com/topic/153683-solved-combining-a-word-with-a-variable-in-a-mysql-query/#findComment-807638 Share on other sites More sharing options...
PFMaBiSmAd Posted April 12, 2009 Share Posted April 12, 2009 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 https://forums.phpfreaks.com/topic/153683-solved-combining-a-word-with-a-variable-in-a-mysql-query/#findComment-807643 Share on other sites More sharing options...
cliftonbazaar Posted April 12, 2009 Author Share Posted April 12, 2009 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 https://forums.phpfreaks.com/topic/153683-solved-combining-a-word-with-a-variable-in-a-mysql-query/#findComment-807741 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.