While loop works on local server but not on the production server

the following works perfectly on the local wamp server but when i’m uploading it to the server used by the client it doesnt do nothing and gives a blank page.
also enabling errorr reporting doesnt help - the page stays blank
(


error_reporting(E_ALL);
ini_set("display_errors", 1);
require ("security.php");

any ideas?



require "conf.inc";
mysql_connect($host, $username, $password);
mysql_select_db($database) or die("Unable to select database");
mysql_query("SET NAMES 'utf8'");

$sss=0;
$user = unserialize($_SESSION['user']);
$uid=$user->get_user_id();
$result2 = mysql_query("SELECT first_name,last_name FROM users WHERE id='".intval($uid)."'");
$row2 = mysql_fetch_array($result2, MYSQL_ASSOC);
$first_name= $row2['first_name'];
$last_name=$row2['last_name'];
$managername=$first_name .  " " . $last_name;
$aid = mysql_real_escape_string($_POST["aid"]);
$aname = $_POST["aname"];

$start_date = mysql_real_escape_string($_POST["start_date"]);
$end_date = mysql_real_escape_string($_POST["end_date"]);
$PaiedByAgent = mysql_real_escape_string($_POST["paied"]);

if($PaiedByAgent==""){die ("יש לרשום כמה שולם על ידי סוכן");}
$recepit = mysql_real_escape_string($_POST["recepit"]);
if($recepit==""){die("יש לרשום מספר חשובנית");}
$debt_sum = mysql_real_escape_string($_POST["DebtSum"]);
if ($PaiedByAgent > $debt_sum)
{
    echo "הסכום שהסוכן משלם גבוהה יותר מהחוב, אין אפשרות לצבור יתרה";
    die;
}
$query = "select * FROM payments WHERE agentID='$aid' AND TourDate BETWEEN '$start_date' AND '$end_date'";
$result = mysql_query($query);

if(!$result){echo mysql_error();}


while ($PaiedByAgent > 0)
{

    while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
        $pid = $row['id'];
        $orderID = $row['orderID'];
        $AgentId = $row['AgentId'];
        $Debt = $row['Debt'];
        echo "pid: ".$pid."<br>";
        echo "orderid: ".$orderID."<br>";
        echo "AgentId: ".$AgentId."<br>";
        echo "debt: ".$debt."<br>";
        }}


        if ($Debt > $PaiedByAgent)
        {
            $Cpay = $PaiedByAgent;
            $Cdebt = $Debt - $Cpay;
$query1 = "UPDATE payments SET " . "Paid = (Paid + " . $Cpay . "), Debt='" . $Cdebt .
                "', receipt = CONCAT_WS('<br/>', receipt," . $recepit .
                "), PayDate =CONCAT_WS('<br/>', PayDate, CURDATE()), ManagerName = CONCAT_WS('<br/>', ManagerName, '".addslashes($managername) ."') WHERE id = '" .
                mysql_real_escape_string($pid) . "' ";
            $result1 = mysql_query($query1);
            if (!$result1)
            {
                echo "error: " . mysql_error();
            } else
            {
           $sss=$sss+1;
            }

            $PaiedByAgent = $PaiedByAgent - $Cpay;
            if ($PaiedByAgent == "0")
            {
                break;
            }

        }
        if ($PaiedByAgent > $Debt)
        {
            $Cpay = $Debt;
            $Cdebt = 0;
            $query1 = "UPDATE payments SET " . "Paid = (Paid + " . $Cpay . "), Debt='" . $Cdebt .
                "', receipt = CONCAT_WS('<br/>', receipt," . $recepit .
                "), PayDate =CONCAT_WS('<br/>', PayDate, CURDATE()), ManagerName = CONCAT_WS('<br/>', ManagerName, '".addslashes($managername) ."') WHERE id = '" .
                mysql_real_escape_string($pid) . "' ";
            $result2 = mysql_query($query1);
            if (!$result2)
            {
                echo "error: " . mysql_error();
            } else
            {

               $sss=$sss+1;
            }
            $PaiedByAgent = $PaiedByAgent - $Cpay;
            if ($PaiedByAgent == "0")
            {
            break;
            }
           continue 1;
          }

        if ($PaiedByAgent == $Debt)
        {
            $Cpay = $PaiedByAgent;
            $Cdebt = $Debt - $Cpay;

           $query1 = "UPDATE payments SET " . "Paid = (Paid + " . $Cpay . "), Debt='" . $Cdebt .
                "', receipt = CONCAT_WS('<br/>', receipt," . $recepit .
                "), PayDate =CONCAT_WS('<br/>', PayDate, CURDATE()), ManagerName = CONCAT_WS('<br/>', ManagerName, '".addslashes($managername) ."') WHERE id = '" .
                mysql_real_escape_string($pid) . "' ";
            $result3 = mysql_query($query1);
            if (!$result3)
            {
                echo "error: " . mysql_error();
            } else
            {
        $sss=$sss+1;
            }

            $PaiedByAgent = $PaiedByAgent - $Cpay;
            if ($PaiedByAgent == "0")
            {
                break;
            }
        }

    }
}


if($sss>0){
    $start_date = implode('-', array_reverse(explode('-', $start_date)));
    $end_date = implode('-', array_reverse(explode('-', $end_date)));
    htmls(1,$aid,$start_date,$end_date,$aname);
}else{htmls(0,$aid,$start_date,$end_date,$aname);}

function htmls($res,$aid,$start_date,$end_date,$aname){
echo "
<!DOCTYPE html PUBLIC \\"-//W3C//DTD XHTML 1.0 Transitional//EN\\" \\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\\">
<html xmlns=\\"http://www.w3.org/1999/xhtml\\">
<head>
<meta http-equiv=\\"Content-Type\\" content=\\"text/html; charset=utf-8\\" />
<title> &#1491;&#1493;&#1495; &#1514;&#1513;&#1500;&#1493;&#1502;&#1497;&#1501;</title>
<link rel=\\"stylesheet\\" href=\\"css/style.css\\"  />
<link rel=\\"stylesheet\\" href=\\"css/menu_style.css\\" type=\\"text/css\\" />

</head>
<body>

";
display_menu_by_level();

if($res=='1'){
    echo("<div class='content'><h2>&#1508;&#1512;&#1496;&#1497; &#1492;&#1514;&#1513;&#1500;&#1493;&#1501; &#1506;&#1493;&#1491;&#1499;&#1504;&#1493;</h2>" );
    echo "<form  method='post' action='report_by_payment2.php'>";
    echo "<input type='hidden' value='$aid' name='aid' />";
    echo "<input type='hidden' value=$aname name='aname' />
    <input type='hidden' value='$start_date' name='start_date' />
<input type='hidden' value='$end_date' name='end_date' />'
<button type='submit'>&#1495;&#1494;&#1493;&#1512;</button>
";

}
else{
    echo "<div class='content'><h2>"."&#1513;&#1490;&#1497;&#1488;&#1492; &#1489;&#1506;&#1491;&#1499;&#1493;&#1503; &#1508;&#1512;&#1496;&#1497; &#1492;&#1514;&#1513;&#1500;&#1493;&#1501;"."</h2>";

}
echo"
</div>
</body>
</html>

";
}


Have you tried to echo/var_dump()/print_r() statements starting after each line to see where the script is dying? You say that the While loop is not working but are you sure that it is even making it to the While loop?

Steve

A blank page usually indicates there is a fatal PHP error in the script.

Make the first line of the script echo LINE. ’ : ’ FILE;die;

If that show the line and file then cut the line and paste it halfway down the script.

If that show then post it in the remaining line half of the script otherwise paste it the previous half of the script.

Repeat until the error is found :slight_smile:

http://php.net/manual/en/errorfunc.configuration.php

Note:

Although display_errors may be set at runtime (with ini_set()), it won’t have any affect if the script has fatal errors. This is because the desired runtime action does not get executed.

SB

echo __LINE__ . ' : ' .  __FILE__; die; 

Missing a dot.

Nice idea, like that one.

apperntley you were right - i didnt check if it go inside the loop.
it didnt get the values it need from the previous page because i closed the mysql connection and still used the mysql_real_escape wich resulted in an empty vars.

thank you all for fast replays and the will to help!

genia,

Glad you found the problem.

John_Betong: Yes that is a nice way to report where a script is making its’ way. Thanks.

Steve

@genia , @ServerStorm and especially @Cups for spotting the syntax error.

Necessity is the Mother of Invention :slight_smile:

I devised the method after struggling with a PHP framework where all pages are derived from a common index.php file… biggest problem is to find which file has the error.