GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 24-Nov-2006, 11:29
Richardknox Richardknox is offline
Junior Member
 
Join Date: Nov 2006
Location: Michigan
Posts: 83
Richardknox is on a distinguished road

Warning: Cannot modify header information - headers already sent by


Hello again,

I am getting this error for one PHP script including another PHP script. And I am not sure what I am doing wrong. I am trying to set up one file to hold my username, password, hostname, and so forth. That way once the databases are working correctly, and if I do any changes, I can just change this file, instead of multiple files.

Here is the php script with the database login info

PHP Code:

<?
// db_connection.php

// First we will set our variables
$dbhostname="database.server.net";
$dbusername="myusername";
$dbpassword="password";
         

?>


Then here is the second php script that works with the database.

PHP Code:

<?
include "db_connection.php";   //Includes Database information
?>
<?php

$dbname="wcdatabase";
$usertable="wctable";

$dblink = mysql_connect($dbhostname,$dbusername, $dbpassword) OR DIE ("Unable to connect to database! Please try again later.");
mysql_select_db($dbname, $dblink);

$_SERVER['HTTP_USER_AGENT'];

// Get the ID number from the end of the ace.php?

$id=$_GET['id'];

// query the database
$query = "SELECT * FROM wcdatabase WHERE id = ($id) LIMIT 0, 30 ";

$result = mysql_query($query,$dblink);

$row = mysql_fetch_assoc($result);

// this is the part that updates the count.

        $row["viewed"]++;
        
$viewed = $row["viewed"];

// This is the part that updates the database.

$query = "UPDATE wcdatabase SET viewed = ($viewed) where id = ($id)";

$result = mysql_query($query, $dblink); 


// This is the part that redirects to the lin URL
$link = $row["link"];

Header("Location: $link");
exit();

?>


I am getting this error, and it points to the "HEADER ("Location: $link"); line.

Any ideas what to do?

Thanks,
Richard
  #2  
Old 24-Nov-2006, 16:03
Richardknox Richardknox is offline
Junior Member
 
Join Date: Nov 2006
Location: Michigan
Posts: 83
Richardknox is on a distinguished road

Re: Warning: Cannot modify header information - headers already sent by


I figured out a solution, but I am not certain if this is a correct one. Or does it leave me open to some type of problems????

This is the way it was in the 1st post.
PHP Code:

<?
// db_connection.php

// First we will set our variables
$dbhostname="database.server.net";
$dbusername="myusername";
$dbpassword="password";
         

?>


This is the revised file.

PHP Code:

<?
// db_connection.php

// First we will set our variables
$dbhostname="database.server.net";
$dbusername="myusername";
$dbpassword="password";


I removed the last "?>" from the 1st php file, and all the error went away. And it actually works.

Now, am I leaving myself open to problems, or something.

Thanks,
Richard
  #3  
Old 24-Nov-2006, 16:31
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 754
admin will become famous soon enough

Re: Warning: Cannot modify header information - headers already sent by


Whenever you send headers, you must ensure no markup (or content) is sent to the browser BEFORE the header is sent.

When you had this:

Code:
?> <?php

there was a newline/carriage return in between the tags.
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
  #4  
Old 24-Nov-2006, 17:07
Richardknox Richardknox is offline
Junior Member
 
Join Date: Nov 2006
Location: Michigan
Posts: 83
Richardknox is on a distinguished road

Re: Warning: Cannot modify header information - headers already sent by


So, how should it have looked?

PHP Code:

<?
// db_connection.php

// First we will set our variables
$dbhostname="database.server.net";
$dbusername="myusername";
$dbpassword="password";
         

?>

 
 

Recent GIDBlogMeeting the local Iraqis by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Program goldfish C Programming Language 6 13-May-2006 13:12
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 13:12
Pcap programming in C++ goal86sg C++ Forum 2 25-Jan-2006 14:02
My program can run,but warning were display on Vc++ fwongmc C Programming Language 5 08-Dec-2004 10:15
link error? pablowablo C++ Forum 14 19-Jun-2004 10:00

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 23:08.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.