Jump to content

Argh can't find the error?


dmccabe

Recommended Posts

Ok so I have a line that is throwing this error and its a simple bit of code:

 

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in C:\wamp\www\tooswift\viewplugs.php on line 9

 

The code is:

while($row = mysql_fetch_array($getcats)) {
	echo "<li><a href=\"viewplugins.php?catid=".$row['id']."\" title=\"View ".$row['name']." category\">".$row['name']"</a></li>"; <--- this is line 9
}

 

It's diving me nuts

 

Edit: I have tried with both \" and '

Link to comment
https://forums.phpfreaks.com/topic/110118-argh-cant-find-the-error/
Share on other sites

echo "<li><a href=\"viewplugins.php?catid=".$row['id']."\" title=\"View ".$row['name']." category\">".$row['name']."</a></li>";
                                                                                                                  ^
                                                                                                                  |
                                                                                                               missing "."

You are missing a concatenation dot . after the second $row['name']

 

You won't believe how many times this happens when simply concatenating variables with strings. Try the following syntax to see if you like it better (it is less prone to syntax errors) -

 

echo "<li><a href=\"viewplugins.php?catid={$row['id']}\" title=\"View {$row['name']} category\">{$row['name']}</a></li>";

Excellent thanks guys,

 

Also lots of thanks for the handy syntax, never knew that before!

 

Now on to the next issue:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\tooswift\viewplugins.php on line 29

 

if (isset($_GET['catid'])) {
$catid = $_GET['catid'];
echo $catid;
$getplugins = mysql_query("SELECT * FROM plugins WHERE `id` = `$catid`");		
echo "<table width=\"100%\">
		<th align='center' colspan='5' id='tablehead'>Plugin Details:</th>
		<tr>
			<td><b>ID</b></td>
			<td><b>Name</b></td>
			<td><b>Author</b></td>
			<td><b>Home Page</b></td>
			<td><b>Version</b></td>
		</tr>
			";
while($row2 = mysql_fetch_array($getplugins)) { <---- line 29
		echo "<tr>
				<td>{$row2['id']}</td>
				<td>{$row2['name']}</td>
				<td>{$row2['author']}</td>
				<td><a href='{$row2['homepage']}' title='link to {$row2['author']}`s webpage'>Home Page</a></td>
				<td>{$row2['version']}</td>
			</tr>";
}
echo "</table>";

}

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.