Aaron Strickland Aaron Strickland - 4 years ago 108
SQL Question

Strict Standards: Only variables should be passed by reference PHP Shopping Cart

i'm currently in the process of creating a PHP shopping cart but keep i'm stuck with the error "Strict Standards: Only variables should be passed by reference PHP Shopping Cart". I've researched the error, found many different explanations as to why this is happening. I can't seem to resolve the issue. Any help would be much appreciated. Please see my code below.

$img=mysql_real_escape_string(end(explode('/',$_POST['img'])));

Answer Source

You need to break up your code instead of doing it all at once, like so:

$imgArr = explode('/',$_POST['img']);
$img = end($imgArr);
$imgEscaped = mysql_real_escape_string($img);

The reason why is that end() expects a variable to be passed by reference, and so you need to assign your explode() to an intermediate variable first.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download