Jump to content

Recommended Posts

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 by Jessica
Link to comment
https://forums.phpfreaks.com/topic/278805-php-error/#findComment-1434241
Share on other sites

 

($_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.

Link to comment
https://forums.phpfreaks.com/topic/278805-php-error/#findComment-1434310
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/278805-php-error/#findComment-1434315
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/278805-php-error/#findComment-1434351
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/278805-php-error/#findComment-1434420
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.