TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 790
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 1
  • Guests: 636
  • Total: 637
  • tino

TP PHP Bloc error, possible php/html code misuse?

Started by lextalionis, October 08, 2009, 03:50:55 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

lextalionis

Link to my site: http://www.motleypixel.com
SMF version: SMF ver. 1.1.9
TP version: TP ver. 1.0 beta 4
Theme name and version: Black Rain
Browser Name and Version: IE 7.0.5730.10
Mods installed: TPReviews, iFrame, YouTube, Ads Management (all current for SMF 1.1.9)
Related Error messages: Parse error: syntax error, unexpected '<' in /home/lexurld/public_html/motleypixel.com/forum/Sources/Load.php(1745) : eval()'d code(48) : eval()'d code on line 1

I was provoked to look and see if there are related html/php block issues that report the above error when I saw this error on my top panel bloc.  I'm curious to know if either this is a normal error due to the bloc selected function (PHP Code) the the code I entered into it or if there's truely an issue with my /sources/load.php file.  I took a look at my Load.php but didn't see anything abnormal at or around line 1745.

Any way, my goal is to trim down and replace this page:  http://www.motleypixel.com/games/index.php with a more simplified top panel bloc.  I've tried both html/javascript and php code type blocs and php results in the above error and html results in just the raw html code being displayed on the top panel bloc.  This is the code I'm starting out with:



<body>
<?

$name = $_GET['PlayerName'];
$score = $_GET['Score'];

$service = "localhost";
$username = "lexurld_pxsmash";
$password = "?????????";
$database = "lexurld_pxsmash";

mysql_connect($service, $username, $password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "SELECT DISTINCT od1.PlayerName, od1.Score, od1.TimeStamp, od1.Level
FROM highscores AS od1
JOIN highscores AS p ON od1.PlayerName = p.PlayerName
WHERE od1.Score = (
SELECT MAX( Score )
FROM highscores AS od2
WHERE od1.PlayerName = od2.PlayerName ) order by od1.score DESC
LIMIT 0 , 100";
$result = mysql_query($query);
$num = mysql_numrows($result);

?>

<strong>TOP 100 PIXELSMASH GLOBAL REAL-TIME SCORES</strong>
<br>
<br>
<center>
<table>
<tr class="header">
<td><strong>Rank</strong></td>
<td><strong>Name</strong></td>
<td><strong>Score</strong></td>
<td><strong>Level</strong></td>
<td><strong>Date</strong></td></tr>

<?

$loopindex = 0;

while ($loopindex < $num) {
    $thisname = mysql_result($result, $loopindex, "PlayerName");
    $thisscore = mysql_result($result, $loopindex, "Score");
    $thislevel = mysql_result($result, $loopindex, "Level");
    $thisdate = mysql_result($result, $loopindex, "TimeStamp");

    $thispos = $loopindex+1;

    echo ("<tr>
        <td align=left><p>$thispos</p></td>
        <td align=center><p>$thisname</p></td>
        <td align=center><p>$thisscore</p></td>
        <td align=center><p>$thislevel</p></td>
        <td align=center><p>$thisdate</p></td>
</tr>\n");

$loopindex++;
}

?>
</body>
</table>
</html>


So, am I doing something obviously wrong?

Thanks,
Roy

G6Cad

You cant have the php tags in the block code as TP render a php block with these tags on auto.

Reformate the code and leave out the php tags and then echo the html parts of your code. and then check if it works

JPDeni

Also, your html is wrong.

Delete

<body>


at the beginning and remove the

</body>


and


</html>


tags at the end.

lextalionis

Okay thanks G6 and JPDeni,

Still using a PHP Code bloc type, I've removed the php tags (this is only the <? ?> tags right?  I've echoed the html as well and removed all the <html><body> tags but I still receive that error when that bloc is displayed. 

Here's the current code:


$name = $_GET['PlayerName'];
$score = $_GET['Score'];

$service = "localhost";
$username = "lexurld_pxsmash";
$password = "???????";
$database = "lexurld_pxsmash";

mysql_connect($service, $username, $password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "SELECT DISTINCT od1.PlayerName, od1.Score, od1.TimeStamp, od1.Level
FROM highscores AS od1
JOIN highscores AS p ON od1.PlayerName = p.PlayerName
WHERE od1.Score = (
SELECT MAX( Score )
FROM highscores AS od2
WHERE od1.PlayerName = od2.PlayerName ) order by od1.score DESC
LIMIT 0 , 100";
$result = mysql_query($query);
$num = mysql_numrows($result);



echo "<strong>TOP 100 PIXELSMASH GLOBAL REAL-TIME SCORES</strong>
<br>
<br>
<center>
<table>
<tr class="header">
<td><strong>Rank</strong></td>
<td><strong>Name</strong></td>
<td><strong>Score</strong></td>
<td><strong>Level</strong></td>
<td><strong>Date</strong></td></tr></table></center>";



$loopindex = 0;

while ($loopindex < $num) {
    $thisname = mysql_result($result, $loopindex, "PlayerName");
    $thisscore = mysql_result($result, $loopindex, "Score");
    $thislevel = mysql_result($result, $loopindex, "Level");
    $thisdate = mysql_result($result, $loopindex, "TimeStamp");

    $thispos = $loopindex+1;

    echo "<table><tr><center>
        <td align=left><p>$thispos</p></td>
        <td align=center><p>$thisname</p></td>
        <td align=center><p>$thisscore</p></td>
        <td align=center><p>$thislevel</p></td>
        <td align=center><p>$thisdate</p></td>
</tr></table></center>";

$loopindex++;
}



Thanks,
Roy

G6Cad

You have doubble quotes  that you need to change to single

these

",

needs to be

',

All the doubble quotes needs to be removed and changed to single quotes

JPDeni

Well, not exactly. Some of the double quotes can be retained.

Try this



$name = $_GET['PlayerName'];
$score = $_GET['Score'];

$service = "localhost";
$username = "lexurld_pxsmash";
$password = "???????";
$database = "lexurld_pxsmash";

mysql_connect($service, $username, $password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "SELECT DISTINCT od1.PlayerName, od1.Score, od1.TimeStamp, od1.Level
FROM highscores AS od1
JOIN highscores AS p ON od1.PlayerName = p.PlayerName
WHERE od1.Score = (
SELECT MAX( Score )
FROM highscores AS od2
WHERE od1.PlayerName = od2.PlayerName ) order by od1.score DESC
LIMIT 0 , 100";
$result = mysql_query($query);
$num = mysql_numrows($result);



echo '<strong>TOP 100 PIXELSMASH GLOBAL REAL-TIME SCORES</strong>
<br>
<br>
<center>
<table>
<tr class="header">
<td><strong>Rank</strong></td>
<td><strong>Name</strong></td>
<td><strong>Score</strong></td>
<td><strong>Level</strong></td>
<td><strong>Date</strong></td></tr>';

$loopindex = 0;

while ($loopindex < $num) {
    $thisname = mysql_result($result, $loopindex, "PlayerName");
    $thisscore = mysql_result($result, $loopindex, "Score");
    $thislevel = mysql_result($result, $loopindex, "Level");
    $thisdate = mysql_result($result, $loopindex, "TimeStamp");

    $thispos = $loopindex+1;

    echo "<tr>
        <td align=left><p>$thispos</p></td>
        <td align=center><p>$thisname</p></td>
        <td align=center><p>$thisscore</p></td>
        <td align=center><p>$thislevel</p></td>
        <td align=center><p>$thisdate</p></td>
</tr>";

$loopindex++;
}
echo '</table></center>';



There were also some html errors, which I fixed.

lextalionis

JPDeni, that did the trick.  I need to brush up on my formatting using echo, but at least now I've got a good start.

You can see it works now:  http://www.motleypixel.com/forum/index.php 

In case you are wondering, a friend created a game called PixelSmash which is using my photos as the backdrops and it has an on-line score DB, it's the score DB I wanted inside of the php bloc.

You can test and try it if you like...it's a light-weight app that passed approval from downloads.com and his stuff is at http://pixelkick.com, but anyway here PixelSmash, it's a fun pass-the-time at work old break-out style game: http://download.cnet.com/PixelSmash/3000-2099_4-10885901.html?part=dl-10885901&subj=dl&tag=button

Thanks again, problem is solved now.

-Roy

JPDeni

I'm glad it worked for you.

I usually use the single quotes and concatenate any variables, but you had the variables within double quotes so it was easier to just leave them that way when possible. It was the first section that had things like


<td class="header">


where the double quotes caused a problem.

I like the game. :)

Ken.

Good job JP and you're right, it is a good game. :up:
" If everything seems under control, you're not going fast enough." - Mario Andretti
Yesterday When I was Young.

This website is proudly hosted on Crocweb Cloud Website Hosting.