...

View Full Version : syntax error



Mihai
03-16-2008, 11:10 AM
<?php
if($_SERVER[PHP_SELF]=="/include/profiles/index.inc.php")
{
header("Location: /index.php");
exit;
}

$directory = getcwd();

$connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect.");
$db = @mysql_select_db($db_name, $connection) or die("Couldn't select database.");

$sql = "SELECT * FROM $tbl_profiles WHERE directory = \"$directory\"";

$result = @mysql_query($sql,$connection) or die("Couldn't execute profile query.");
$num=mysql_num_rows($result);

while ($row = mysql_fetch_array($result)) {

$profile_id = $row['profile_id'];
$dark_color = $row['dark_color'];
$light_color = $row['light_color'];
$panel_text = $row['panel_text'];
$table_color = $row['table_color'];
$font_color = $row['font_color'];
$font_style = $row['font_style'];
$font_size = $row['font_size'];
$profile_url = $row['profile_url'];
$page_name = $row['page_name'];
$ratings = $row['ratings'];
$p_name = $row['p_name'];
$location = $row['location'];
$gender = $row['gender'];
$age = $row['age'];
$marital = $row['marital'];
$about_me = $row['about_me'];
$hobbies = $row['hobbies'];
// HP/MP/TP bars.
$stathp = ceil($userrow['currenthp'] / $userrow 'maxhp' * 100);
if ($userrow['maxmp'] != 0) { $statmp = ceil($userrow['currentmp'] / $userrow['maxmp'] * 100); } else { $statmp = 0; }
$stattp = ceil($userrow["currenttp"] / $userrow["maxtp"] * 100);
$stattable = "<table width=\"100\"><tr><td width=\"33%\">\n";
$stattable .= "<table cellspacing=\"0\" cellpadding=\"0\"><tr><td style=\"padding:0px; width:15px; height:100px; border:solid 1px black; vertical-align:bottom;\">\n";
if ($stathp >= 66) { $stattable .= "<div style=\"padding:0px; height:".$stathp."px; border-top:solid 1px black; background-image:url(images/bars_green.gif);\"><img src=\"images/bars_green.gif\" alt=\"\" /></div>"; }
if ($stathp < 66 && $stathp >= 33) { $stattable .= "<div style=\"padding:0px; height:".$stathp."px; border-top:solid 1px black; background-image:url(images/bars_yellow.gif);\"><img src=\"images/bars_yellow.gif\" alt=\"\" /></div>"; }
if ($stathp < 33) { $stattable .= "<div style=\"padding:0px; height:".$stathp."px; border-top:solid 1px black; background-image:url(images/bars_red.gif);\"><img src=\"images/bars_red.gif\" alt=\"\" /></div>"; }
$stattable .= "</td></tr></table></td><td width=\"33%\">\n";
$stattable .= "<table cellspacing=\"0\" cellpadding=\"0\"><tr><td style=\"padding:0px; width:15px; height:100px; border:solid 1px black; vertical-align:bottom;\">\n";
if ($statmp >= 66) { $stattable .= "<div style=\"padding:0px; height:".$statmp."px; border-top:solid 1px black; background-image:url(images/bars_green.gif);\"><img src=\"images/bars_green.gif\" alt=\"\" /></div>"; }
if ($statmp < 66 && $statmp >= 33) { $stattable .= "<div style=\"padding:0px; height:".$statmp."px; border-top:solid 1px black; background-image:url(images/bars_yellow.gif);\"><img src=\"images/bars_yellow.gif\" alt=\"\" /></div>"; }
if ($statmp < 33) { $stattable .= "<div style=\"padding:0px; height:".$statmp."px; border-top:solid 1px black; background-image:url(images/bars_red.gif);\"><img src=\"images/bars_red.gif\" alt=\"\" /></div>"; }
$stattable .= "</td></tr></table></td><td width=\"33%\">\n";
$stattable .= "<table cellspacing=\"0\" cellpadding=\"0\"><tr><td style=\"padding:0px; width:15px; height:100px; border:solid 1px black; vertical-align:bottom;\">\n";
if ($stattp >= 66) { $stattable .= "<div style=\"padding:0px; height:".$stattp."px; border-top:solid 1px black; background-image:url(images/bars_green.gif);\"><img src=\"images/bars_green.gif\" alt=\"\" /></div>"; }
if ($stattp < 66 && $stattp >= 33) { $stattable .= "<div style=\"padding:0px; height:".$stattp."px; border-top:solid 1px black; background-image:url(images/bars_yellow.gif);\"><img src=\"images/bars_yellow.gif\" alt=\"\" /></div>"; }
if ($stattp < 33) { $stattable .= "<div style=\"padding:0px; height:".$stattp."px; border-top:solid 1px black; background-image:url(images/bars_red.gif);\"><img src=\"images/bars_red.gif\" alt=\"\" /></div>"; }
$stattable .= "</td></tr></table></td>\n";
$stattable .= "</tr><tr><td>HP</td><td>MP</td><td>TP</td></tr></table>\n";
$userrow["statbars"] = $stattable;

// Now make numbers stand out if they're low.
if ($userrow["currenthp"] <= ($userrow["maxhp"]/5)) { $userrow["currenthp"] = "<blink><span class=\"highlight\"><b>*".$userrow["currenthp"]."*</b></span></blink>"; }
if ($userrow["currentmp"] <= ($userrow["maxmp"]/5)) { $userrow["currentmp"] = "<blink><span class=\"highlight\"><b>*".$userrow["currentmp"]."*</b></span></blink>"; }

$spellquery = doquery("SELECT id,name,type FROM `members`","spells");
$userspells = explode(",",$userrow["spells"]);
$userrow["magiclist"] = "";
while ($spellrow = mysql_fetch_array($spellquery)) {
$spell = false;
foreach($userspells as $a => $b) {
if ($b == $spellrow["id"] && $spellrow["type"] == 1) { $spell = true; }
}
if ($spell == true) {
$userrow["magiclist"] .= "<a href=\"index.php?do=spell:".$spellrow["id"]."\">".$spellrow["name"]."</a><br />";
}
}
if ($userrow["magiclist"] == "") { $userrow["magiclist"] = "None";
}
}

?>

abduraooft
03-16-2008, 11:25 AM
Please wrap PHP codes using the PHP tag (http://www.codingforums.com/showthread.php?t=68462)
<?php
if($_SERVER[PHP_SELF]=="/include/profiles/index.inc.php")
{
header("Location: /index.php");
exit;
}

$directory = getcwd();

$connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect.");
$db = @mysql_select_db($db_name, $connection) or die("Couldn't select database.");

$sql = "SELECT * FROM $tbl_profiles WHERE directory = \"$directory\"";

$result = @mysql_query($sql,$connection) or die("Couldn't execute profile query.");
$num=mysql_num_rows($result);

while ($row = mysql_fetch_array($result)) {

$profile_id = $row['profile_id'];
$dark_color = $row['dark_color'];
$light_color = $row['light_color'];
$panel_text = $row['panel_text'];
$table_color = $row['table_color'];
$font_color = $row['font_color'];
$font_style = $row['font_style'];
$font_size = $row['font_size'];
$profile_url = $row['profile_url'];
$page_name = $row['page_name'];
$ratings = $row['ratings'];
$p_name = $row['p_name'];
$location = $row['location'];
$gender = $row['gender'];
$age = $row['age'];
$marital = $row['marital'];
$about_me = $row['about_me'];
$hobbies = $row['hobbies'];
// HP/MP/TP bars.
$stathp = ceil($userrow['currenthp'] / $userrow 'maxhp' * 100);
if ($userrow['maxmp'] != 0) { $statmp = ceil($userrow['currentmp'] / $userrow['maxmp'] * 100); } else { $statmp = 0; }
$stattp = ceil($userrow["currenttp"] / $userrow["maxtp"] * 100);
$stattable = "<table width=\"100\"><tr><td width=\"33&#37;\">\n";
$stattable .= "<table cellspacing=\"0\" cellpadding=\"0\"><tr><td style=\"padding:0px; width:15px; height:100px; border:solid 1px black; vertical-align:bottom;\">\n";
if ($stathp >= 66) { $stattable .= "<div style=\"padding:0px; height:".$stathp."px; border-top:solid 1px black; background-image:url(images/bars_green.gif);\"><img src=\"images/bars_green.gif\" alt=\"\" /></div>"; }
if ($stathp < 66 && $stathp >= 33) { $stattable .= "<div style=\"padding:0px; height:".$stathp."px; border-top:solid 1px black; background-image:url(images/bars_yellow.gif);\"><img src=\"images/bars_yellow.gif\" alt=\"\" /></div>"; }
if ($stathp < 33) { $stattable .= "<div style=\"padding:0px; height:".$stathp."px; border-top:solid 1px black; background-image:url(images/bars_red.gif);\"><img src=\"images/bars_red.gif\" alt=\"\" /></div>"; }
$stattable .= "</td></tr></table></td><td width=\"33%\">\n";
$stattable .= "<table cellspacing=\"0\" cellpadding=\"0\"><tr><td style=\"padding:0px; width:15px; height:100px; border:solid 1px black; vertical-align:bottom;\">\n";
if ($statmp >= 66) { $stattable .= "<div style=\"padding:0px; height:".$statmp."px; border-top:solid 1px black; background-image:url(images/bars_green.gif);\"><img src=\"images/bars_green.gif\" alt=\"\" /></div>"; }
if ($statmp < 66 && $statmp >= 33) { $stattable .= "<div style=\"padding:0px; height:".$statmp."px; border-top:solid 1px black; background-image:url(images/bars_yellow.gif);\"><img src=\"images/bars_yellow.gif\" alt=\"\" /></div>"; }
if ($statmp < 33) { $stattable .= "<div style=\"padding:0px; height:".$statmp."px; border-top:solid 1px black; background-image:url(images/bars_red.gif);\"><img src=\"images/bars_red.gif\" alt=\"\" /></div>"; }
$stattable .= "</td></tr></table></td><td width=\"33%\">\n";
$stattable .= "<table cellspacing=\"0\" cellpadding=\"0\"><tr><td style=\"padding:0px; width:15px; height:100px; border:solid 1px black; vertical-align:bottom;\">\n";
if ($stattp >= 66) { $stattable .= "<div style=\"padding:0px; height:".$stattp."px; border-top:solid 1px black; background-image:url(images/bars_green.gif);\"><img src=\"images/bars_green.gif\" alt=\"\" /></div>"; }
if ($stattp < 66 && $stattp >= 33) { $stattable .= "<div style=\"padding:0px; height:".$stattp."px; border-top:solid 1px black; background-image:url(images/bars_yellow.gif);\"><img src=\"images/bars_yellow.gif\" alt=\"\" /></div>"; }
if ($stattp < 33) { $stattable .= "<div style=\"padding:0px; height:".$stattp."px; border-top:solid 1px black; background-image:url(images/bars_red.gif);\"><img src=\"images/bars_red.gif\" alt=\"\" /></div>"; }
$stattable .= "</td></tr></table></td>\n";
$stattable .= "</tr><tr><td>HP</td><td>MP</td><td>TP</td></tr></table>\n";
$userrow["statbars"] = $stattable;

// Now make numbers stand out if they're low.
if ($userrow["currenthp"] <= ($userrow["maxhp"]/5)) { $userrow["currenthp"] = "<blink><span class=\"highlight\"><b>*".$userrow["currenthp"]."*</b></span></blink>"; }
if ($userrow["currentmp"] <= ($userrow["maxmp"]/5)) { $userrow["currentmp"] = "<blink><span class=\"highlight\"><b>*".$userrow["currentmp"]."*</b></span></blink>"; }

$spellquery = doquery("SELECT id,name,type FROM `members`","spells");
$userspells = explode(",",$userrow["spells"]);
$userrow["magiclist"] = "";
while ($spellrow = mysql_fetch_array($spellquery)) {
$spell = false;
foreach($userspells as $a => $b) {
if ($b == $spellrow["id"] && $spellrow["type"] == 1) { $spell = true; }
}
if ($spell == true) {
$userrow["magiclist"] .= "<a href=\"index.php?do=spell:".$spellrow["id"]."\">".$spellrow["name"]."</a><br />";
}
}
if ($userrow["magiclist"] == "") { $userrow["magiclist"] = "None";
}
}

?> and give exact error and the line number

Red Leader
03-16-2008, 11:36 AM
Greetings comrade. Your problem is such:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/fatman/public_html/test/syntax.php on line 39

Now that means the problem can be found near line 39 (probably the $userrow array missing square brackets around its key):


$stathp = ceil($userrow['currenthp'] / $userrow 'maxhp' * 100);

As a suggestion I would recommend enabling error reporting via error_reporting(E_ALL) at the beginning of your script when you have a problem.

Mihai
03-16-2008, 11:45 AM
<php
// HP/MP/TP bars.
$stathp = ceil($userrow['currenthp'] / $userrow 'maxhp' * 100);
if ($userrow['maxmp'] != 0) { $statmp = ceil($userrow ['currentmp'] / $userrow['maxmp'] * 100); } else { $statmp = 0; }
$stattp = ceil($userrow["currenttp"] / $userrow["maxtp"] * 100);
$stattable = "<table width=\"100\"><tr><td width=\"33%\">\n";
$stattable .= "<table cellspacing=\"0\" cellpadding=\"0\"><tr><td style=\"padding:0px; width:15px; height:100px; border:solid 1px black; vertical-align:bottom;\">\n";
if ($stathp >= 66) { $stattable .= "<div style=\"padding:0px; height:".$stathp."px; border-top:solid 1px black; background-image:url(images/bars_green.gif);\"><img src=\"images/bars_green.gif\" alt=\"\" /></div>"; }
if ($stathp < 66 && $stathp >= 33) { $stattable .= "<div style=\"padding:0px; height:".$stathp."px; border-top:solid 1px black; background-image:url(images/bars_yellow.gif);\"><img src=\"images/bars_yellow.gif\" alt=\"\" /></div>"; }
if ($stathp < 33) { $stattable .= "<div style=\"padding:0px; height:".$stathp."px; border-top:solid 1px black; background-image:url(images/bars_red.gif);\"><img src=\"images/bars_red.gif\" alt=\"\" /></div>"; }
$stattable .= "</td></tr></table></td><td width=\"33%\">\n";
$stattable .= "<table cellspacing=\"0\" cellpadding=\"0\"><tr><td style=\"padding:0px; width:15px; height:100px; border:solid 1px black; vertical-align:bottom;\">\n";
if ($statmp >= 66) { $stattable .= "<div style=\"padding:0px; height:".$statmp."px; border-top:solid 1px black; background-image:url(images/bars_green.gif);\"><img src=\"images/bars_green.gif\" alt=\"\" /></div>"; }
if ($statmp < 66 && $statmp >= 33) { $stattable .= "<div style=\"padding:0px; height:".$statmp."px; border-top:solid 1px black; background-image:url(images/bars_yellow.gif);\"><img src=\"images/bars_yellow.gif\" alt=\"\" /></div>"; }
if ($statmp < 33) { $stattable .= "<div style=\"padding:0px; height:".$statmp."px; border-top:solid 1px black; background-image:url(images/bars_red.gif);\"><img src=\"images/bars_red.gif\" alt=\"\" /></div>"; }
$stattable .= "</td></tr></table></td><td width=\"33%\">\n";
$stattable .= "<table cellspacing=\"0\" cellpadding=\"0\"><tr><td style=\"padding:0px; width:15px; height:100px; border:solid 1px black; vertical-align:bottom;\">\n";
if ($stattp >= 66) { $stattable .= "<div style=\"padding:0px; height:".$stattp."px; border-top:solid 1px black; background-image:url(images/bars_green.gif);\"><img src=\"images/bars_green.gif\" alt=\"\" /></div>"; }
if ($stattp < 66 && $stattp >= 33) { $stattable .= "<div style=\"padding:0px; height:".$stattp."px; border-top:solid 1px black; background-image:url(images/bars_yellow.gif);\"><img src=\"images/bars_yellow.gif\" alt=\"\" /></div>"; }
if ($stattp < 33) { $stattable .= "<div style=\"padding:0px; height:".$stattp."px; border-top:solid 1px black; background-image:url(images/bars_red.gif);\"><img src=\"images/bars_red.gif\" alt=\"\" /></div>"; }
$stattable .= "</td></tr></table></td>\n";
$stattable .= "</tr><tr><td>HP</td><td>MP</td><td>TP</td></tr></table>\n";
$userrow["statbars"] = $stattable;

// Now make numbers stand out if they're low.
if ($userrow["currenthp"] <= ($userrow["maxhp"]/5)) { $userrow["currenthp"] = "<blink><span class=\"highlight\"><b>*".$userrow["currenthp"]."*</b></span></blink>"; }
if ($userrow["currentmp"] <= ($userrow["maxmp"]/5)) { $userrow["currentmp"] = "<blink><span class=\"highlight\"><b>*".$userrow["currentmp"]."*</b></span></blink>"; }

$spellquery = doquery("SELECT id,name,type FROM `members`","spells");
$userspells = explode(",",$userrow["spells"]);
$userrow["magiclist"] = "";
while ($spellrow = mysql_fetch_array($spellquery)) {
$spell = false;
foreach($userspells as $a => $b) {
if ($b == $spellrow["id"] && $spellrow["type"] == 1) { $spell = true; }
}
if ($spell == true) {
$userrow["magiclist"] .= "<a href=\"index.php?do=spell:".$spellrow["id"]."\">".$spellrow["name"]."</a><br />";
}
}
if ($userrow["magiclist"] == "") { $userrow["magiclist"] = "None";
}
}

?>
only this part of the script does have errors .
How can i change this line ?
$stathp = ceil($userrow['currenthp'] / $userrow 'maxhp' * 100); ?
My error is Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /index.inc.php on line 39

Red Leader
03-16-2008, 11:50 AM
$stathp = ceil($userrow['currenthp'] / $userrow 'maxhp' * 100);



$stathp = ceil($userrow['currenthp'] / $userrow['maxhp'] * 100);

Red Leader
03-16-2008, 11:51 AM
Crime.

Mihai
03-16-2008, 11:57 AM
Warning: Division by zero in /index.inc.php on line 39

Warning: Division by zero in /index.inc.php on line 41

Fatal error: Call to undefined function doquery() in index.inc.php on line 65

Mihai
03-16-2008, 12:04 PM
how can i enable error reporting via error_reporting(E_ALL) ?:confused:

Red Leader
03-16-2008, 12:08 PM
Warning: Division by zero in /index.inc.php on line 39

On line 39 $userrow['maxhp'] is 0. This is a probelm. Find out where $userrow is defined ( I don't see it anywhere in your script).


$stathp = ceil($userrow['currenthp'] / $userrow['maxhp'] * 100);



Warning: Division by zero in /index.inc.php on line 41

On line 41 $userrow['maxhp'] is 0. This is a probelm. Find out where $userrow is defined ( I don't see it anywhere in your script).


$stattp = ceil($userrow["currenttp"] / $userrow["maxtp"] * 100);



Fatal error: Call to undefined function doquery() in index.inc.php on line 65

The doquery() function is never defined. Either a) Define it or b) Include it.

Red Leader
03-16-2008, 12:11 PM
how can i enable error reporting via error_reporting(E_ALL) ?:confused:

If you're seeing stuff like


Warning: Division by zero in /index.inc.php on line 39

Warning: Division by zero in /index.inc.php on line 41

Fatal error: Call to undefined function doquery() in index.inc.php on line 65

then it is enabled.

The warnings and errors are pretty helpful. If it says "Problem at line 39," go to line 39 and figure it out.

Inigoesdr
03-16-2008, 09:22 PM
Please remember to read the stickies for this forum. In particular the one about using
tags (http://www.codingforums.com/showthread.php?t=68462) when posting code.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum