Record Update Problem

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");
?>
dereksheahanAsked:
Who is Participating?
 
maUruConnect With a Mentor Commented:
 <input type="hidden" name="MM_insert" value="nokia_return">
not
  <input type="hidden" name="MM_insert" value="form1">
0
 
hiteshgupta1Commented:
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
 
hiteshgupta1Commented:
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
dereksheahanAuthor Commented:
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
 
justaphaseCommented:
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
 
levyukCommented:
This line might be the problem because it is trying to change the header

header(sprintf("Location: %s", $insertGoTo));
0
 
Khanh DoanConnect With a Mentor Senior DeveloperCommented:
 $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
 
radiohedCommented:
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
 
maUruCommented:
post GSM_backup.php for us.
0
 
maUruCommented:
<?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
 
hiteshgupta1Commented:
>> dereksheahan,
is ur problem solved??
haven't heard nething from u ?

0
 
dereksheahanAuthor Commented:
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
 
dereksheahanAuthor Commented:
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
 
dereksheahanAuthor Commented:
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
 
maUruCommented:
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
 
dereksheahanAuthor Commented:
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
 
dereksheahanAuthor Commented:
Great Thanks maUru, should have seen that one!
I'll split the points because I was using bonmat86's layout.
Cheers,
D
0
 
maUruCommented:
sounds good to me ;p
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.