Search code examples
phpphp-parse-error

Parse error in php code


I am getting

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)

error at the following line of php code..pls can anyone explain the problem.

   echo "<tr><td><a href=\"$row['link']\"><img src=\"$row['image']\" title=\"$row['game']\" width=\"68\" height \"57\" /></a></td><td><a href=\"$row['link']\">$row['game']</a> </td><td> $row['total']</td></tr>";

Solution

  • Please for the love of legibility, use single quotes when using a large amount of double quotes in the string, and concatenate your variables. Otherwise you end up with loads of \ in your string and it will be harder to spot variables:

    echo '  <tr>
                <td>
                    <a href="'.$row['link'].'">
                        <img src="'.$row['image'].'" title="'.$row['game'].'" width="68" height="57" />
                    </a>
                </td>
                <td>
                    <a href="'.$row['link'].'">'.$row['game'].'</a>
                </td>
                <td>'.$row['total'].'</td>
            </tr>';