Xager Posted May 6, 2009 Share Posted May 6, 2009 I have been getting this error: Warning: Cannot modify header information - headers already sent in /home/xager/public_html/srag/dev/index2.php on line 53 (exact copy and past) I have searched, for 3 days, trying to get answers to this. I have check for blank spaces, checked every single thing that I can find, tested, checked again, deleted, started again... and on and on. So I'm tearing my hair out at this error. I do not know PHP all that well. I am using Dreamweaver CS4 and have created quite a few other websites in the same way, but recently this one is just messing up. The follow is the page that I am working on. I will also have about 9 other pages with pretty much the same setup. <?php virtual('/Connections/srag_conn.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) { $updateSQL = sprintf("UPDATE home SET header=%s, content=%s WHERE id=%s", GetSQLValueString($_POST['header'], "text"), GetSQLValueString($_POST['content'], "text"), GetSQLValueString($_POST['id'], "int")); mysql_select_db($database_srag_conn, $srag_conn); $Result1 = mysql_query($updateSQL, $srag_conn) or die(mysql_error()); $updateGoTo = "success.html"; if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo)); } mysql_select_db($database_srag_conn, $srag_conn); $query_Recordset1 = "SELECT * FROM home"; $Recordset1 = mysql_query($query_Recordset1, $srag_conn) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> <!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> <title>Stanthorpe Regional Art Gallery</title> <link href="../style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="spar"></div> <div id="home"><a href="index.php">HOME</a></div> <div id="exhibitions"><a href="exhibitions.php">EXHIBITIONS</a></div> <div id="collection"><a href="collection.php">COLLECTION</a></div> <div id="events"><a href="events.php">EVENTS</a></div> <div id="public"><a href="public.php">PUBLIC<br /> PROGRAMS</a></div> <div id="membership"><a href="membership.php">MEMBERSHIP</a></div> <div id="contact"><a href="contact.php">CONTACT</a></div> <div id="homebb"></div> <div id="content"> <div id="logo"></div> <div id="container"> <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1"> <table align="center"> <tr valign="baseline"> <td nowrap="nowrap" align="right">Header:</td> <td><input type="text" name="header" value="<?php echo ($row_Recordset1['header']); ?>" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Content:</td> <td><input type="text" name="content" value="<?php echo ($row_Recordset1['content']); ?>" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"> </td> <td><input type="submit" value="Update record" /></td> </tr> </table> <input type="hidden" name="MM_update" value="form1" /> <input type="hidden" name="id" value="<?php echo $row_Recordset1['id']; ?>" /> </form> <p> </p> </div> </div> </body> </html> <?php mysql_free_result($Recordset1); ?> Any help is greatly appreciated! Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 6, 2009 Share Posted May 6, 2009 The whole error message states where the output is being started at. You would need to post that information if you want someone else to help you with the problem. Quote Link to comment Share on other sites More sharing options...
Ammer Posted May 7, 2009 Share Posted May 7, 2009 I ran into the same exact problem with Dreamweaver CS4. I finally figured it out. Instead of using: <?php virtual('/Connections/srag_conn.php'); ?> to call your connections file use: <?php include($_SERVER['DOCUMENT_ROOT']."/Connections/srag_conn.php"); ?> I really dont understand how the latter fixes the problem, but it does. So from my experience there is nothing wrong with your connections include file, the entire problem is generated by using virtual as oppposed to $_SERVER to call the connection script include. Can anyone explain why one would cause the header problem while the other solution works? If anyone can provide an answer for that I can bypass any future problems because by default, everytime you create a database connection, Dreamweaver inserts the virtual connection method, causing the header error. Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.