Jump to content

Script not working


Go to solution Solved by Jacques1,

Recommended Posts

Oh Great GURU's of the PHP Relm, please help!

 

I have this script and when I run it I get a blank screen.

Every thing looks correct don't know what's wrong.

 

SCRIPT:

<?php
include "config.php";

echo '<html>';
echo '<head>
    <style>

    p.pos_right {
        position: relative;
        left: 250px;
        top: 100px;
    }

    h3.pos_right {
        position: relative;
        left: 450px;
        top: 100px;
    }

    </style>
    </head>';

echo '<body>';

echo '<h3 class="pos_right">Weekly Report for <script type="text/javascript"> var d=new Date(); var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday", "Saturday"); var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December"); document.write(weekday[d.getDay()] + " "); document.write(monthname[d.getMonth()] + " "); document.write(d.getDate() + ", "); document.write(d.getFullYear()); </script></h3>';

$result = mysqli_query("SELECT * FROM data1 order by tpts desc");

echo '<p class="pos_right">
<table border="1">
    <thead>
        <tr>
            <td align="center" width="50">Rank</td>
            <td align="center" width="50">Total<br>Pts</td>
            <td align="center" width="100">Name</td>
            <td align="center" width="75">Winnings</td>
            <td align="center" width="75">High<br>Hand</td>
            <td align="center" width="75">50-50</td>
            <td align="center" width="75">Total</td>
            <td align="center" width="50">Wks<br>Plyd</td>
            <td align="center" width="50">In Top<br>7</td>
            <td align="center" width="75">% in Top 7</td>
            <td align="center" width="75">Won /<br>Loss</td>
        <tr>
    </thead>';

while($row = mysqli_fetch_array($result))
{
    echo "<tr>";
    echo "<td>" .['tpts']. "</td>";
    echo "<td>" .['name']. "</td>";
    echo "<td>" "$" .['winning']. "</td>";
    echo "<td>" "$" .['high']. "</td>";
    echo "<td>" "$" .['fty']. "</td>";
    echo "<td>" "$" .['total']. "</td>";
    echo "<td>" .['weeks']. "</td>";
    echo "<td>" .['t7']. "</td>";
    echo "<td>" .['pt7']."%" "</td>";
    echo "<td>" "$" .['wl']. "</td>";
    echo "</tr>";
}

echo "</table>";

mysqli_close($conn);

echo '</body>';
echo '</html>';
?>
Edited by cyberRobot
added [code][/code] tags
Link to comment
https://forums.phpfreaks.com/topic/301071-script-not-working/
Share on other sites

Based on a quick look, you have some syntax errors in the echo statements here:

while($row = mysqli_fetch_array($result))
  {
 
 echo "<tr>";
 echo "<td>" .['tpts']. "</td>";
 echo "<td>" .['name']. "</td>";
 echo "<td>" "$" .['winning']. "</td>";
 echo "<td>" "$" .['high']. "</td>";
 echo "<td>" "$" .['fty']. "</td>";
 echo "<td>" "$" .['total']. "</td>";
 echo "<td>" .['weeks']. "</td>";
 echo "<td>" .['t7']. "</td>";
 echo "<td>" .['pt7']."%" "</td>";
 echo "<td>" "$" .['wl']. "</td>";
 echo "</tr>";
}
Link to comment
https://forums.phpfreaks.com/topic/301071-script-not-working/#findComment-1532385
Share on other sites

your php code contains a number of syntax/parse errors, some incorrect array references, and wrong usage of mysqli_query statement.

 

you need to have php's error_reporting set to E_ALL and display_errors set to ON in the php.ini on your development system to get php to report and display all the errors it detects. due to the syntax/parse errors in your main file, these two settings cannot be set in your main code because your main code never runs for this type of error.

 

the string concatenation you are doing inside the while(){} loop is where most of the problems are. you are missing some concatenation dots OR you should just put everything inside of a php double-quoted string and forget about concatenation.

 

you also need to specify the array name inside that same code. all the array references need to have $row as part of them.

 

the php errors, after you turn them on, should help you find the remaining problems in the code.

Edited by mac_gyver
Link to comment
https://forums.phpfreaks.com/topic/301071-script-not-working/#findComment-1532386
Share on other sites

scrapped that whole script.

went to this one.

<?PHP
include "config.php";

//THIS SECTION WORKS
$sqld = "INSERT data2 (attend, payout, total)\n"
    . " SELECT sumofattend,\n"
    . " sumofpayout,\n"
    . " (sumofpayout - sumofattend) AS net_total\n"
    . " FROM (Select (SUM(attend) * 20) AS sumofattend,\n"
    . " SUM(payout) AS sumofpayout\n"
    . " FROM data\n"
    . " GROUP BY playersid) AS u";

$res11 = mysqli_query( $conn, $sqld ) or exit( mysqli_error($conn) );

$sqle = "INSERT data3 (t7, att)\n"
    . " SELECT sum(points > 0) as t7, sum(attend) as att\n"
    . " FROM data\n"
    . " GROUP BY playersid";
$res12 = mysqli_query( $conn, $sqle ) or exit( mysqli_error($conn) );

$sqlf = "INSERT data4 (pt7)\n"
    . " SELECT round(sum(t7 / att) * 100,0)\n"
    . " FROM data3\n"
    . " GROUP BY data3id";
$res13 = mysqli_query( $conn, $sqlf ) or exit( mysqli_error($conn) );

$sqlg = "INSERT data1 (`tpts`, `name`, `winning`, `high`, `fty`, `total`, `weeks`, `t7`, `pt7`, `wl`) \n"
    . " SELECT sum( a.points ), b.name, sum( a.payout ), sum( a.hh ), sum( a.ff ), sum( a.payout + a.hh + a.ff ), sum( a.attend ), d.t7, ab.pt7, c.total \n"
    . " FROM data a, players b, data2 c, data3 d, data4 ab \n"
    . " WHERE a.playersid = b.playersid and a.playersid = c.data2id and a.playersid = d.data3id and a.playersid = ab.data4id \n"
    . " GROUP BY b.name";

$res11 = mysqli_query( $conn, $sqlg ) or exit( mysqli_error($conn) );

echo mysqli_error();

// END OF THIS SECTION WORKS2


//THIS SECTION DOES NOT WORK
$query = "SELECT * FROM data1 order by tpts desc";
while($row = mysqli_fetch_array($query)) {
    echo "<tr>
            <td><font color='white'></td>
            <td><font color='white'>.$row['tpts'].</td>
            <td><font color='white'>.$row['name'].</td>
            <td><font color='white'>.$row['winning'].</td>
            <td><font color='white'>.$row['high'].</td>
            <td><font color='white'>.$row['fty'].</td>
            <td><font color='white'>.$row['total'].</td>
            <td><font color='white'>.$row['weeks']?></td>
            <td><font color='white'>.$row['t7'].</td>
            <td><font color='white'>.$row['pt7'].</td>
            <td><font color='white'>.$row['wl'].</td>
    </tr>";
}
?>

Same problem no screen output.

Edited by cyberRobot
fixed the [code][/code] tags - note the square brakets
Link to comment
https://forums.phpfreaks.com/topic/301071-script-not-working/#findComment-1532397
Share on other sites

Also note that you still have quite a few syntax errors in the following while loop:

while($row = mysqli_fetch_array($query)) {
    echo "<tr>
            <td><font color='white'></td>
            <td><font color='white'>.$row['tpts'].</td>
            <td><font color='white'>.$row['name'].</td>
            <td><font color='white'>.$row['winning'].</td>
            <td><font color='white'>.$row['high'].</td>
            <td><font color='white'>.$row['fty'].</td>
            <td><font color='white'>.$row['total'].</td>
            <td><font color='white'>.$row['weeks']?></td>
            <td><font color='white'>.$row['t7'].</td>
            <td><font color='white'>.$row['pt7'].</td>
            <td><font color='white'>.$row['wl'].</td>
    </tr>";
}
 
It should look more like this: 
while($row = mysqli_fetch_array($query)) {
    echo "<tr>
            <td><font color='white'></td>
            <td><font color='white'>" . $row['tpts']    . "</td>
            <td><font color='white'>" . $row['name']    . "</td>
            <td><font color='white'>" . $row['winning'] . "</td>
            <td><font color='white'>" . $row['high']    . "</td>
            <td><font color='white'>" . $row['fty']     . "</td>
            <td><font color='white'>" . $row['total']   . "</td>
            <td><font color='white'>" . $row['weeks']   . "</td>
            <td><font color='white'>" . $row['t7']      . "</td>
            <td><font color='white'>" . $row['pt7']     . "</td>
            <td><font color='white'>" . $row['wl']      . "</td>
    </tr>";
}

 

Link to comment
https://forums.phpfreaks.com/topic/301071-script-not-working/#findComment-1532401
Share on other sites

You need to call mysqli_query before you can fetch any rows

 

@gw32 - when you call mysqli_query, as suggested by Barand, you'll need to store the result set identifier. That identifier needs to be passed to mysqli_fetch_array() in the following line of code:

while($row = mysqli_fetch_array($query)) {

More information can be found here:

http://php.net/manual/en/mysqli-result.fetch-array.php

Link to comment
https://forums.phpfreaks.com/topic/301071-script-not-working/#findComment-1532402
Share on other sites

  • Solution

The bigger picture is that you need to stop writing spaghetti code.

 

Right now, you have JavaScript code within 90s HTML markup within PHP code, next to CSS within HTML within PHP. No wonder you spend most of your time struggling with syntax errors! You've reached the point where you no longer understand your own code.

 

JavaScript code and CSS declarations belong into external files. This will massively reduce the complexity and size of your PHP scripts, making syntax errors much less likely. The PHPHTML pasta can be untangled with a template engine like Twig, which will also fix dozens of cross-site scripting vulnerabilities in your current code (it seems you haven't even thought about security before).

 

While it's theoretically possible to generate dynamic web pages with pure PHP, this requires a lot of discipline and security awareness. I don't recommend it.

 

Last but not least, you should replace your current code editor with a proper IDE (integrated development environment) like Netbeans or Eclipse. This will warn you immediately when you fudge up the syntax, giving you a chance to fix the error yourself.

Link to comment
https://forums.phpfreaks.com/topic/301071-script-not-working/#findComment-1532405
Share on other sites

Great advice and nice and soft slap on the hands.

Eclipse will not run on my mac, something about JVD versions, did what it said to do and still no run.

 

Will try Netbeans.

 

As far as spaghetti code, I just sat down last week to try to develop a web site from my spreadsheets.

My spreadsheets have all the right formulas and put things where they belong.

 

Will let you know how things progress.

 

Thanks for your help.

  • Like 1
Link to comment
https://forums.phpfreaks.com/topic/301071-script-not-working/#findComment-1532423
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.