chrisshortys Posted January 25, 2013 Share Posted January 25, 2013 Hi there, I am very new to the world of coding but am slowly creating pages! Now I have been doing work with PHP and mySQL this week and I have a question that I cannot find the answer for(probably because I am searching for the wrong phrase!). What I want to be able to do is to take a piece of information from a html form and convert this into PHP a variable but with a modification. e.g. From the html table the data is stored in the html variable "comp" $tablename = $_POST[comp] Now what I actually want the variable to end up as is something like BL_comp or comp_BL How do you place the letters before or after the html/PHP variable? All help would be greatly appreciated! Chris Link to comment https://forums.phpfreaks.com/topic/273642-creating-php-variables-with-fixed-strings/ Share on other sites More sharing options...
Jessica Posted January 25, 2013 Share Posted January 25, 2013 Search the PHP manual for "concatenation". Also use quotes around your array keys when they are strings. Read the whole PHP chapter on strings. Link to comment https://forums.phpfreaks.com/topic/273642-creating-php-variables-with-fixed-strings/#findComment-1408226 Share on other sites More sharing options...
chrisshortys Posted January 25, 2013 Author Share Posted January 25, 2013 Thanks! I shall give that a read tomorrow afternoon! As a quick follow on question then would the following work? <?php $tablename = $_POST[comp]; echo "BL_{$tablename}"; ?> Link to comment https://forums.phpfreaks.com/topic/273642-creating-php-variables-with-fixed-strings/#findComment-1408227 Share on other sites More sharing options...
Jessica Posted January 25, 2013 Share Posted January 25, 2013 It might if you defined $a, and used quotes on your array key. Link to comment https://forums.phpfreaks.com/topic/273642-creating-php-variables-with-fixed-strings/#findComment-1408228 Share on other sites More sharing options...
chrisshortys Posted January 25, 2013 Author Share Posted January 25, 2013 So say the html variable in comp is "test" does this code change the Variable $tablename from "test" to "BL_test"? <?php $tablename = $_POST[comp]; echo "BL_{$tablename}"; ?> and yes I shall sort the quotes out Link to comment https://forums.phpfreaks.com/topic/273642-creating-php-variables-with-fixed-strings/#findComment-1408232 Share on other sites More sharing options...
Jessica Posted January 25, 2013 Share Posted January 25, 2013 Did you try it? Link to comment https://forums.phpfreaks.com/topic/273642-creating-php-variables-with-fixed-strings/#findComment-1408233 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.