Topic: xajax error Output has already been sent to the browser

Hi, my function SQL_update below was working properly to update data in the browser but when I created an SQL_delete function below I received this error below.  In order to fix the error I had to move the $xajax->processRequest(); statement to the top of the file but then the SQL_update function stopped working.  What might be the cause?   Where should the
$xajax->processRequest() statement be placed in order for both functions below working properly, or do I need to move my SQL_delete function to another location?

Thanks,
Aaron


  "Output has already been sent to the browser at testajaxupdate.php:4. Please make sure the command $xajax->processRequest() is placed before this."




<?php


//connect to database
$hostname =
$username =
$password =
$dbName =

$cnx = mysql_connect($hostname,$username,$password) or DIE("DATABASE FAILED TO RESPOND.");
mysql_select_db($dbName) or DIE("Table unavailable");

require ('../xajax_core/xajax.inc.php');
$xajax = new xajax();
$xajax->processRequest();


//Parse post data
if ($_POST[delete])  {
   Parse_post($_POST);
}


//Parse incoming post vars and call SQL_delete
function Parse_post ($post_it) {

foreach ($post_it as $key => $value) {
    if (substr($key,0,2) == "PK") {
        $pos = strrpos($key, "_");
        $strlength = strlen($key);
        $db_id = substr($key,$pos+1);   
        SQL_delete ($db_id);
    }
} //for each
} //end Parse_post

//Delete record from database
function SQL_delete ($save_id) {

//delete record
    $db1 = "DELETE from Tracking WHERE PK='$save_id'";
    $cur1 = mysql_query($db1) or die(mysql_error());
   
}

//Parse incoming data and update database and use innerHTML to update client side html
function SQL_Update ($saveid,$the_value) {

//parse right side of string for PK
    $pos = strrpos($saveid, "_");
    $strlength = strlen($saveid);
    $db_id = substr($saveid,$pos+1);

//parse left side of string for database field
    $db_field = substr($saveid, 0, $pos);

//update database
    $db1 = "Update Tracking Set $db_field='$the_value' where PK='$db_id'";

//instantiate Response object and write client side html
    $objResponse = new xajaxResponse();
    $objResponse->addAssign($saveid,'innerHTML', $the_value);

    return $objResponse;
           
}  //end SQL_Update


$xajax->registerFunction("SQL_Update");


/*
    Section: processRequest
   
    This will detect an incoming xajax request, process it and exit.  If this is
    not an xajax request, then it is a request to load the initial contents of the page
    (HTML).
   
    Everything prior to this statement will be executed upon each request (whether it
    is for the initial page load or a xajax request.  Everything after this statement
    will be executed only when the page is first loaded.
*/



?>

<html>
<head>
    <link rel="stylesheet" type="text/css" href="demo1.css" />

    <title>Demo</title>
<?php
    // output the xajax javascript. This must be called between the head tags
    $xajax->printJavascript();
?>


   
</head>
<body style="text-align:center;">

<?php


echo '<?xml version="1.0" encoding="UTF-8"?>';

//Select and display all field names in database
   $cur = MYSQL_QUERY ("select * from Tracking",$cnx);

    if ($cur == "") {echo "No query executed"; exit; }
    $number = MYSQL_NUM_ROWS($cur); //number of rows returned
    if ($number < 1) { echo "No records found<br>"; exit;} //no max value found, exit
   
    $numfields = mysql_num_fields($cur);
   
    echo "<FORM NAME='ADD_DELETE' METHOD='POST' action='masterlog.php'>";
    echo "<TABLE BORDER=1 CELLPADDING=1 CELLSPACING=0>";
        echo "<TR class=bg><th>.</th><th>Time</th><th >Date</th><th >UPS</th><th >SMC</th><th >PM</th><th>PPC</th>
        <th>BowLast</th><th>BowFirst</th><th>BowPHone</th><th>Spouse</th><th>Email</th><th>City</th><th>County</th><th>State</th><th>Method</th>
        <th>Status</th><th>CallBack</th><th>Hot1</th><th>Hot2</th><th>Chal1</th><th>Chal2</th><th>Possible Investor</th><th>Comments</th></TR>";
       

    //display all records
    while ($row=mysql_fetch_row($cur)) { //get a row
        for ($count = 0; $count < $numfields; $count++) {
              $fieldname = MYSQL_FIELD_NAME($cur,$count);
                       
            switch ($fieldname) {
               
            case "PK":
                $saveid = $row[$count];
                echo "<TR>";
                echo "<td><input type=checkbox name='$fieldname" . "_" . "$saveid'" .  " id='$fieldname" . "_" . "$saveid'  /></td>";
                break;
            case "Comments":
                echo "<td width=25><input type=text class=text SIZE=70 name='$fieldname" . "_" . "$saveid'" .  " id='$fieldname" . "_" . "$saveid' value='$row[$count]' onchange='xajax_SQL_Update(this.id,this.value);'></td>";
                echo "</TR>";
                break;
            case "BowPhoneNo":
                    echo "<td width=25><input type=text class=text SIZE=10 name='$fieldname" . "_" . "$saveid'" .  " id='$fieldname" . "_" . "$saveid' value='$row[$count]' onchange='xajax_SQL_Update(this.id,this.value);'></td>";
                    break;
            case "Time":
                   echo "<td width=25><input type=text class=text SIZE=5 name='$fieldname" . "_" . "$saveid'" .  " id='$fieldname" . "_" . "$saveid' value='$row[$count]' onchange='xajax_SQL_Update(this.id,this.value);'></td>";
                    break;
              
            case "City":
                echo "<td width=25><input type=text class=text SIZE=10 name='$fieldname" . "_" . "$saveid'" .  " id='$fieldname" . "_" . "$saveid' value='$row[$count]' onchange='xajax_SQL_Update(this.id,this.value);'></td>";
                break;   
              
            default:
                   echo "<td width=25><input type=text class=text SIZE=5 name='$fieldname" . "_" . "$saveid'" .  " id='$fieldname" . "_" . "$saveid' value='$row[$count]' onchange='xajax_SQL_Update(this.id,this.value);'></td>";
            } //end switch
           
         }  //end for
    } //end while
   
    echo "<td><input type='submit' name='delete' value='Delete'></td>";
    echo "</TABLE>";
    echo "</FORM>";
   
//close database
//mysql_close($cnx);


?>



</body>
</html>

2 (edited by totty 2008-05-05 2:28:06 PM)

Re: xajax error Output has already been sent to the browser

I have met this problem months ago!and the error occured,but it has nothing to with the place of the $xajax->processRequest() statement .
the reason of the problem is that the HTML files include the BOM, so there is a </br> tag that you can no see in the editor at the top of the HTML file . 
you could open the HTML files with the DreamWeaver and change the property of the page ,and let the BOM sign gone!
msn:  mioim.com@hotmail.com

Re: xajax error Output has already been sent to the browser

i also have this problem

and  i have delete the </br>

but the problem still have~

i really don't know why?
who will tell me what's the problem?

Re: xajax error Output has already been sent to the browser

did you have whitespace before your <?php ?> tags ?
please doublecheck all your files