Pergunta

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>";
Foi útil?

Solução 2

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>';

Outras dicas

The problem is the array variables you have embedded in the string.

When you embed an array variable in a string, you must enclose it in curly braces, like so:

$stringvar = "blah blah {$arrayvar['element']} blah blah";

Therefore, in your code, $row['link'] and all the other $row elements need to be enclosed in {} braces.

Note that you can (and should) do this for all variables in a string, but it is mandatory for array elements.

In addition, you have a missing escaping slash on one of the quotes in your string: \"57". This will also cause a syntax error.

Hope that helps.

To assist with debugging: this is quite a long and complicated line of code, with lots of escaped quotes etc that can make it hard to debug in one go (especially when it has multiple issues with it).

My advice would be to debug it by spitting it down into more manageable chunks. You'll still get the same errors for the same reasons, but it'll be easier to find them. You can join the line back up into a single long line again once it's fixed.

Finally, I would recommend using a decent IDE or text editor that supports syntax highlighting. This will give you much better feedback on where the errors are.

try this

   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>";

missing escape qoute

You missed one trailing slash

 height =\"57\"

Try this one

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>';

Try this :

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>';
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>";

It's always a good practice to use the { } to contain the variables into a string, especially here because it is an array value.

Moreover there was an error just here: height =\"57" => height =\"57\"

In alternative you could write like below for a more eligibility:

echo '<a href="'.$row['link'].'">...';
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top