PDA

View Full Version : Parse error, unexpected ';'



jasonhardwick
September 8th, 2007, 07:09 PM
I know i have a problem in line 145, just dont know how to fix it

$mailto = $row["email_address"] ? '<a href="mailto: {$row["email_address"]}" target=\"_blank\"> {$row["email_address"]} </a>';


<?
$DBhost = "XXX";
$DBuser = "XXX";
$DBpass = "XXX";
$DBName = "XXX";
$table = "XXX";
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

@mysql_select_db("$DBName") or die("Unable to select database $DBName");

$sql = "SELECT *
FROM XXX
ORDER BY name
DESC LIMIT 0,1000";

$result = mysql_query($sql);

if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}

if (mysql_num_rows($result) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}

// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop
// Note: If you put extract($row); inside the following loop, you'll
// then create $userid, $fullname, and $userstatus
echo "<TABLE cellspacing=\"4\" cellpadding=\"5\">";
while ($row = mysql_fetch_assoc($result)) {
$image = $row["image"] ? '<img src="' . $row["image"] . '">' : '';
$mailto = $row["email_address"] ? '<a href="mailto: {$row["email_address"]}" target=\"_blank\"> {$row["email_address"]} </a>';

echo "<TR>";
echo $row["name"];
echo "<br/>";
echo "<TD align=\"left\" valign=\"top\" <span class=\"style3\">"$mailto;
echo "<br/>";
echo "<align=\"left\" valign=\"top\" <span class=\"style3\">".$row["body"]."</TD>";
echo "</TR>";

}

echo "</TABLE>";

mysql_free_result($result);

?>

hl
September 8th, 2007, 07:15 PM
Replace echo "<TD align=\"left\" valign=\"top\" <span class=\"style3\">"$mailto; with echo "<TD align=\"left\" valign=\"top\" <span class=\"style3\">" . $mailto;.

You need a . between " and $mailto.\

jasonhardwick
September 8th, 2007, 07:46 PM
thanks for that...

i'm still getting this error:

Parse error: parse error, unexpected ';' in /home/content/s/c/o/scopeadmin/html/miami/contact.php on line 145

SteelLionPHP
September 8th, 2007, 11:27 PM
Sorry, a bit confused what you are trying to do but if line 145 is
$mailto = ? '<a href="mailto: {$row["email_address"]}" target=\"_blank\"> {$row["email_address"]} </a>';

that might be a bit messy, try

$mailto= $row["email_address"];
print "<A HREF=\"mailto: $mailto\" target=\"_blank\">$mailto</A>";

simplistik
September 9th, 2007, 12:24 AM
yea without knowing what line 145 is, I'd agree with both the two replies thus far. I'm not sure what you're tryin to do but this is how I'd do what I think you're tryin' to do:

HOWEVER, in general I'd consider this


echo "<TR>";
echo $row["name"];
echo "<br/>";
echo "<TD align=\"left\" valign=\"top\" <span class=\"style3\">"$mailto;
echo "<br/>";
echo "<align=\"left\" valign=\"top\" <span class=\"style3\">".$row["body"]."</TD>";
echo "</TR>";

pure garbage, the markup that it's supposed to echo would NEVER work properly. You can't just drop a span inside another tag without closing it out first.


I'll comment out what you have and replace it with what it should probably be.


//$mailto = $row["email_address"] ? '<a href="mailto: {$row["email_address"]}" target=\"_blank\"> {$row["email_address"]} </a>';
$email = 'email@email.com';
$mailto = '<a href="mailto:'.$email.'" target="_blank">'.$email.'</a>';


//echo "<TD align=\"left\" valign=\"top\" <span class=\"style3\">"$mailto;...
echo '<tr>';
echo '<td align="left" valign="top">'.$row['name'].'<br/><span class="style3">'.$mailto.'</span>';
echo '<br/>';
echo $row['body'];
echo '</td>';
echo '</tr>';

SteelLionPHP
September 9th, 2007, 02:32 PM
Awesome..simplistik, thats what Im talking about.
Always use PHP's power to put anything you want in a variable to echo so you dont have to mess around with alot of Parse errors.

:thumb: :thumb:

binime
September 9th, 2007, 06:57 PM
i think the error lies in:


$mailto = $row["email_address"] ? '<a href="mailto: {$row["email_address"]}" target=\"_blank\"> {$row["email_address"]} </a>';

try


$mailto = ( isset( $row['email_address'] ) ) ? $row["email_address"] : "<a href=\"mailto: {$row['email_address']}\" target=\"_blank\"> {$row['email_address']} </a>";