Jump to content

[SOLVED] T_ENCAPSED_AND_WHITESPACE problem


biggerboy

Recommended Posts

I have what is below and when I run it, it returns T_ENCAPSED_AND_WHITESPACE

 

$query = "insert into images set realname='$filename_orig', user='$username', size='$filesize', used='$date', type='$filetype', desc='$desc', ip='$_SERVER['REMOTE_ADDR']', private='1', report='0'";

Link to comment
https://forums.phpfreaks.com/topic/74510-solved-t_encapsed_and_whitespace-problem/
Share on other sites

ip='$_SERVER['REMOTE_ADDR']'

 

The above snippet is what is causing the problem.  You have single quotes that denote strings to MySQL but then you have other single quotes that denote the index into the $_SERVER array.  It is always recommended when embedding variables into double-quoted strings to enclose them in curly brackets.

 

ip='{$_SERVER['REMOTE_ADDR']}'

What part would be most helpful? Here is the last one I tried. Could it be something with the strings that are causing it?

 

$query = 'insert into images set realname='".$filename_orig."', 
user='".$username."', size='".$filesize."', used='".$date."',
type='".$filetype."', desc='".$desc."', ip='".{$_SERVER['REMOTE_ADDR']}."', 
private='1', report='0'';

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.