?
Solved

Record Update Problem

Posted on 2006-06-16
18
Medium Priority
?
434 Views
Last Modified: 2008-02-01
Hi all,
Could anyone tell me how to sort out this error: Warning: Cannot modify header information - headers already sent by (output started at /home/reachate/public_html/Connections/GSM_backup.php:4) in /home/reachate/public_html/Remote/nokiaremotereturnlive.php on line 57
Not sure what to do with it?
Here's the page and the connection file.
Thanks so much,
D

<?php require_once('../Connections/GSM_backup.php'); ?>
<?php


// Deconcatenate the varaiables in the 'os0' post field...
$customVar = $_REQUEST['custom'];
$arrayVar = explode("---",$customVar);
$IMEI = $arrayVar[0];
$username = $arrayVar[1];
$email = $arrayVar[2];


function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO nokia_removal_table (nokia_username, nokia_email_add, nokia_IMEI_nr) VALUES (%s, %s, %s)",
                       GetSQLValueString($_POST['nokia_username'], "text"),
                       GetSQLValueString($_POST['nokia_email_add'], "text"),
                       GetSQLValueString($_POST['nokia_IMEI_nr'], "int"));

  mysql_select_db($database_GSM_mobile, $dbh);
  $Result1 = mysql_query($insertSQL, $dbh) or die(mysql_error());

  $insertGoTo = "../mainpage.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
$name = $_POST['txt_name'] ;
?><!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=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form id="nokia_return" name="nokia_return" method="post" action="">
 
</form>

<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
  <table align="center">
    <tr valign="baseline">
      <td nowrap align="right">Username:</td>
      <td><input name="nokia_username" type="text" value="<?php echo $username; ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Email Address:</td>
      <td><input type="text" name="nokia_email_add" value="<?php echo $email; ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">IMEI Number</td>
      <td><input type="text" name="nokia_IMEI_nr" value="<?php echo $IMEI; ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><input type="submit" value="Insert record"></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1">
</form>

<p>&nbsp;</p>
</body>
</html>


And here's the connection (it works fine for other pages)
<?php
$dbh=mysql_connect ("localhost", "reachate_mainuse", "xxx") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("reachate_corkgsmdb");
?>
0
Comment
Question by:dereksheahan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 3
  • +4
18 Comments
 
LVL 8

Expert Comment

by:hiteshgupta1
ID: 16919228
This error comes when something is sent to the browser before you session started. Check to see if you have any empty lines at the top of your code
0
 
LVL 8

Expert Comment

by:hiteshgupta1
ID: 16919236
0
 

Author Comment

by:dereksheahan
ID: 16919666
Hi hiteshgupta1,
I can't seem to understand what it is I need to change in order to make it work. I've checked the code and have no spaces at the top of the page. I'm not using session variables like the other example. I am however passing variables to the page and taking them out of the POST_array. Is it the $InsertGoTo Statement that is the problem?
Thanks,
D
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:justaphase
ID: 16920175
What we ment is something like "echo", "print", "sprint", "sprintf" etc..

like the line 44 u have in your code:
$insertSQL = sprintf("INSERT INTO nokia_removal_table (nokia_username, nokia_email_add, nokia_IMEI_nr) VALUES (%s, %s, %s)",

if it isn't the "sprintf" its something inside the GSM_backup.php that doing that, some echo or print...
0
 
LVL 7

Expert Comment

by:levyuk
ID: 16920457
This line might be the problem because it is trying to change the header

header(sprintf("Location: %s", $insertGoTo));
0
 
LVL 10

Assisted Solution

by:Khanh Doan
Khanh Doan earned 800 total points
ID: 16920986
 $insertSQL = sprintf("INSERT INTO nokia_removal_table (nokia_username, nokia_email_add, nokia_IMEI_nr) VALUES (%s, %s, %s)",
                       GetSQLValueString($_POST['nokia_username'], "text"),
                       GetSQLValueString($_POST['nokia_email_add'], "text"),
                       GetSQLValueString($_POST['nokia_IMEI_nr'], "int"));


change to

$nokia_username = addslashes($_POST['nokia_username']);
$nokia_email_add = addslashes($_POST['nokia_email_add']);
$nokia_IMEI_nr = addslashes($_POST['nokia_IMEI_nr']);

  $insertSQL = "INSERT INTO nokia_removal_table (nokia_username, nokia_email_add, nokia_IMEI_nr) VALUES (' . $nokia_username  . ', ' . $nokia_email_add . ', ' . $nokia_IMEI_nr . ')";

and I hope that there don't have any echo or smth like this in your GSM_backup.php
Bonmat86.
0
 
LVL 1

Expert Comment

by:radiohed
ID: 16921435
Your code is using the header function, which won't work because some output has already been sent to the browser. PHP is telling you that the output started in home/reachate/public_html/Connections/GSM_backup.php on line 4. You should look there for your problem.
0
 
LVL 7

Expert Comment

by:maUru
ID: 16933865
post GSM_backup.php for us.
0
 
LVL 7

Expert Comment

by:maUru
ID: 16933879
<?php
$dbh=mysql_connect ("localhost", "reachate_mainuse", "xxx") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("reachate_corkgsmdb");
?>

the problem is probably here, right after the ?> which means your have something like a newline or space.

delete everything before the ?> and type:
<?php
$dbh=mysql_connect ("localhost", "reachate_mainuse", "xxx") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("reachate_corkgsmdb"); ?>

making sure NOTHING comes after the ?>, no newline, try openening a new file and copying it there and saving it again in case a stray control character has somehow been inserted.
0
 
LVL 8

Expert Comment

by:hiteshgupta1
ID: 16939981
>> dereksheahan,
is ur problem solved??
haven't heard nething from u ?

0
 

Author Comment

by:dereksheahan
ID: 16982577
Hi guys,
Sorry was on holiday there for a week, thats why I haven't been in contact :) Unfortunatley none of the above solves the problem. maUru, I looked at my connection file and the last line already had the php close statement on it.
I'm sure it is this part which is causing the problem:
$insertGoTo = "../mainpage.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo)); // this line in particular

I just need to know how to change this so that the page is still redirected to mainpage.php on update.
Thanks so much,
D
0
 

Author Comment

by:dereksheahan
ID: 16982580
Hi bonmat86,
I've tried changing the page to this but it still gives me the same error:

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "nokia_return")) {
$nokia_username = addslashes($_POST['nokia_username']);
$nokia_email_add = addslashes($_POST['nokia_email_add']);
$nokia_IMEI_nr = addslashes($_POST['nokia_IMEI_nr']);

$insertSQL = "INSERT INTO nokia_removal_table (nokia_username, nokia_email_add, nokia_IMEI_nr) VALUES (' . $nokia_username  . ', ' . $nokia_email_add . ', ' . $nokia_IMEI_nr . ')";

  mysql_select_db($database_GSM_mobile, $dbh);
  $Result1 = mysql_query($insertSQL, $dbh) or die(mysql_error());

  $insertGoTo = "../mainpage.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
0
 

Author Comment

by:dereksheahan
ID: 16982776
Sorry ignore my last comment. When I try the above script in my last post it doesn't generate an error but reloads the same page and doesn't update the DB. Any suggestions as to what I might be doing wrong?
Thanks,
D
0
 
LVL 7

Expert Comment

by:maUru
ID: 16983245
first of all, MM_insert (is probably not set which is why you are getting reloaded to the same page

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "nokia_return")) {

header(sprintf("Location: %s", $insertGoTo));

this is NOT your problem, line 4 of gsmbackup is.

try and use hard coded the gsm backup, dont include it:

<?
$dbh=mysql_connect ("localhost", "reachate_mainuse", "xxx") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("reachate_corkgsmdb");

// Deconcatenate the varaiables in the 'os0' post field...
$customVar = $_REQUEST['custom'];
....
....
....
....
0
 

Author Comment

by:dereksheahan
ID: 16983410
Hi maUru,
Yes I have the MM_insert statement there. Thanks, I've also hard coded the connection but I think that was working now anyways.

Here's the code I have. It gives no error but doesn't update the DB at all. It also still returns to the same page.
Thanks,
D

<?php $dbh=mysql_connect ("localhost", "corkgsm_admin", "xxx") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("corkgsm_corkgsmdb"); ?>
<?php


// Deconcatenate the varaiables in the 'os0' post field...
$customVar = $_REQUEST['custom'];
$arrayVar = explode("---",$customVar);
$IMEI = $arrayVar[0];
$username = $arrayVar[1];
$email = $arrayVar[2];


function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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_insert"])) && ($_POST["MM_insert"] == "nokia_return")) {
$nokia_username = addslashes($_POST['nokia_username']);
$nokia_email_add = addslashes($_POST['nokia_email_add']);
$nokia_IMEI_nr = addslashes($_POST['nokia_IMEI_nr']);

$insertSQL = "INSERT INTO nokia_removal_table (nokia_username, nokia_email_add, nokia_IMEI_nr) VALUES (' . $nokia_username  . ', ' . $nokia_email_add . ', ' . $nokia_IMEI_nr . ')";

  mysql_select_db($database_GSM_mobile, $dbh);
  $Result1 = mysql_query($insertSQL, $dbh) or die(mysql_error());

  $insertGoTo = "../mainpage.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
$name = $_POST['txt_name'] ; ?>

<!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=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>


<form  id="nokia_return" method="post" name="nokia_return" action="<?php echo $editFormAction; ?>">
  <table align="center">
    <tr valign="baseline">
      <td nowrap align="right">Username:</td>
      <td><input name="nokia_username" type="text" value="<?php echo $username; ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Email Address:</td>
      <td><input type="text" name="nokia_email_add" value="<?php echo $email; ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">IMEI Number</td>
      <td><input type="text" name="nokia_IMEI_nr" value="<?php echo $IMEI; ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><input type="submit" value="Insert record"></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1">
</form>

<p>&nbsp;</p>
</body>
</html>





0
 
LVL 7

Accepted Solution

by:
maUru earned 1040 total points
ID: 16983995
 <input type="hidden" name="MM_insert" value="nokia_return">
not
  <input type="hidden" name="MM_insert" value="form1">
0
 

Author Comment

by:dereksheahan
ID: 16984609
Great Thanks maUru, should have seen that one!
I'll split the points because I was using bonmat86's layout.
Cheers,
D
0
 
LVL 7

Expert Comment

by:maUru
ID: 16984690
sounds good to me ;p
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question