skicrud Posted April 14, 2009 Share Posted April 14, 2009 Does anyone know the proper syntax for $_POST['C_'$var]? I need to concat the variable name of a post with a prefix and I keep getting syntax errors. Quote Link to comment https://forums.phpfreaks.com/topic/154038-solved-concatenation/ Share on other sites More sharing options...
Maq Posted April 14, 2009 Share Posted April 14, 2009 Use a dot, just like any other string. Quote Link to comment https://forums.phpfreaks.com/topic/154038-solved-concatenation/#findComment-809712 Share on other sites More sharing options...
mandred Posted April 14, 2009 Share Posted April 14, 2009 $_POST['C_' . $var]; or $_POST["C_$var"]; Quote Link to comment https://forums.phpfreaks.com/topic/154038-solved-concatenation/#findComment-809714 Share on other sites More sharing options...
skicrud Posted April 14, 2009 Author Share Posted April 14, 2009 the $_POST[C_.$var] produces the following error: Parse error: parse error, expecting `']'' and the $_POST['C_$var'] returns this error: Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' Quote Link to comment https://forums.phpfreaks.com/topic/154038-solved-concatenation/#findComment-809722 Share on other sites More sharing options...
Maq Posted April 14, 2009 Share Posted April 14, 2009 You're missing single quotes. Quote Link to comment https://forums.phpfreaks.com/topic/154038-solved-concatenation/#findComment-809724 Share on other sites More sharing options...
skicrud Posted April 14, 2009 Author Share Posted April 14, 2009 Where? Quote Link to comment https://forums.phpfreaks.com/topic/154038-solved-concatenation/#findComment-809735 Share on other sites More sharing options...
Maq Posted April 14, 2009 Share Posted April 14, 2009 Please read previous posts, mandred provided you with the exact answer... $_POST['C_' . $var]; Quote Link to comment https://forums.phpfreaks.com/topic/154038-solved-concatenation/#findComment-809739 Share on other sites More sharing options...
PFMaBiSmAd Posted April 14, 2009 Share Posted April 14, 2009 Both things you tried do not match the examples that were posted. Go back and read the examples. Where quotes are and if they are single-quotes or double-quotes matters in programming because computers only do exactly what your code tells them to do. Quote Link to comment https://forums.phpfreaks.com/topic/154038-solved-concatenation/#findComment-809741 Share on other sites More sharing options...
skicrud Posted April 14, 2009 Author Share Posted April 14, 2009 echo "insert into log job_number=$job_number, user=$theid, item_checked=$key, item_comment=$_POST['C_'.$var]"; produces an error but echo "insert into log job_number=$job_number, user=$theid, item_checked=$key, item_comment="; echo $_POST['C_'.$var]; does not. Quote Link to comment https://forums.phpfreaks.com/topic/154038-solved-concatenation/#findComment-809776 Share on other sites More sharing options...
Maq Posted April 14, 2009 Share Posted April 14, 2009 Please use tags around code. You never mentioned it was in a query... Try: echo "insert into log job_number=$job_number, user=$theid, item_checked=$key, item_comment='{$_POST['C_'.$var]}'"; Quote Link to comment https://forums.phpfreaks.com/topic/154038-solved-concatenation/#findComment-809784 Share on other sites More sharing options...
skicrud Posted April 14, 2009 Author Share Posted April 14, 2009 Sorry and thanks Quote Link to comment https://forums.phpfreaks.com/topic/154038-solved-concatenation/#findComment-809797 Share on other sites More sharing options...
Maq Posted April 14, 2009 Share Posted April 14, 2009 Sorry and thanks You're still new here, don't worry about it. It just makes the code easier to read by formatting and highlighting code properly. If everything properly works now, please mark as [sOLVED]. Quote Link to comment https://forums.phpfreaks.com/topic/154038-solved-concatenation/#findComment-809831 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.