Solved

Record Update Problem

Posted on 2006-06-16
18
427 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
  • 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
 
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 200 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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 260 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…

709 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now