ctg Posted June 5, 2013 Share Posted June 5, 2013 am geting a parse error: syntax error, unexpected T-ENCAPSED-AND WHITE SPACE, EXPECTING'] IN LINE 8 whis is ($_POST[Name]', '$_POST[Phone No.]', '$_POST', '$_POST[subject]', '$_POST[Message]')"; Quote Link to comment Share on other sites More sharing options...
Jessica Posted June 5, 2013 Share Posted June 5, 2013 (edited) You should post the entire line of code, as that's not anywhere near valid PHP. But I can assume that's part of an SQL query string. A. you should not use $_POST variables directly in the string. B. You should really switch to using prepared statements via mysqli/PDO. C. You also need single quotes for each array key. $_POST['Email Address'] is valid. You'll need to study up on string concatenation, interpolation, and escaping quotes to make that string work. D. You're also missing a single quote at the beginning of the set. Edited June 5, 2013 by Jessica Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 5, 2013 Share Posted June 5, 2013 An array reference must look like: $_array['indexname'] which you are not doing Quote Link to comment Share on other sites More sharing options...
DavidAM Posted June 5, 2013 Share Posted June 5, 2013 ($_POST[Name]', '$_POST[Phone No.]', '$_POST[Email Address]', '$_POST[Subject]', '$_POST[Message]')"; That appears to be only part of a statement. We can't really tell you much without more context. Post more code, several lines BEFORE the error line and several lines after. But PLEASE, PLEASE use ... tags. Quote Link to comment Share on other sites More sharing options...
teynon Posted June 5, 2013 Share Posted June 5, 2013 That appears to be only part of a statement. We can't really tell you much without more context. Post more code, several lines BEFORE the error line and several lines after. But PLEASE, PLEASE use ... tags. More context is probably necessary to fix all the follow up problems here, but the code posted shows what ginerjm was saying. You must surround the array indexes with quotes ($_POST['Name']', '$_POST['Phone No.']', '$_POST['Email Address']', '$_POST['Subject']', '$_POST['Message']')"; Once you do that, you will most likely get an error because you are using arrays in a string. To fix that, you can surround the variables with {} ('{$_POST['Name']}', '{$_POST['Phone No.']}', '{$_POST['Email Address']}', '{$_POST['Subject']}', '{$_POST['Message']}')"; Also note that you are missing the first quote on the $_POST['Name']. Additionally, since this is probably a mysql query string, you should look into sanitizing your input data or using PDO or MySQLi prepared statements. Once you read this, you'll probably say to yourself the same thing that 99% of new people here say, which is that's too complicated, i'm just going to use it like this for now. But, if you want to do yourself a favor, learn PDO or MySQLi now. mysql_blah is deprecated and you'll have to learn the new stuff eventually anyways, if you ever want to upgrade when the new stuff comes out. Quote Link to comment Share on other sites More sharing options...
grissom Posted June 6, 2013 Share Posted June 6, 2013 It looks like you are trying to do a mysql insert statement. From the bit I can see, try putting a single quote between the first left hand bracket and the first dollar sign. You may also need another right hand bracket right at the end of the line before the semicolon. If that fails, please can you post the full mysql query you are trying to execute. Good luck. Quote Link to comment Share on other sites More sharing options...
grissom Posted June 6, 2013 Share Posted June 6, 2013 An array reference must look like: $_array['indexname'] which you are not doing Not necessarily, if it's inside a mysql statement Quote Link to comment Share on other sites More sharing options...
DavidAM Posted June 6, 2013 Share Posted June 6, 2013 When an array element is referenced INSIDE double quotes, the rules are slightly different. $a = array('one' => 1, 'two' => 2); echo "First: '$a[one]' -- Second: '$a[two]'" . PHP_EOL; echo "First: '$a['one']' -- Second: '$a['two']'" . PHP_EOL; echo "First: '{$a['one']}' -- Second: '{$a['two']}'" . PHP_EOL; In this code, line 3 will work (without warnings), line 7 will work. Line 5 will produce the "unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING " error. PHP does not recognize CONSTANTS inside a double-quoted string, so the unknown constant warning will not be triggered by line 3. PHP requires curly braces for "complex" variable expressions inside a double-quoted string, as show in line 7 -- This is the recommended method for using arrays in double-quoted strings. Since we do not the context of that partial line of code, we really cannot answer the question. It could be an SQL statement, it could be an ECHO statement, it could be a misplaced double-quote on the end of some other invalid expression. Quote Link to comment 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.