Jump to content


Photo

PHP Guestbook Error Code


  • Please log in to reply
3 replies to this topic

#1 bryanptcs

bryanptcs
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 26 October 2006 - 08:37 PM

I am using simple_guestbook php to do a very simple post to a mysql database.  I have the posting working, and it can retrieve the information, but when you submit the form the following error message comes up:

Warning: Cannot modify header information - headers already sent by (output started at /home/ww2palm/public_html/commentcard.php:7) in /home/ww2palm/public_html/commentcard.php on line 137

The following is the code for the php, excluding the database login info:

<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">

    <p><label for="txtName">Name:</label><br />
    <input type="text" title="Enter your name" name="txtName" /></p>

<p><label for="rate">How would you rate us:</label><br />
  <input type="radio" name="rate" value="1">
1 <input type="radio" name="rate" value="2">
2 <input type="radio" name="rate" value="3">
3 <input type="radio" name="rate" value="4">
4 <input type="radio" name="rate" value="5">
5
<br>
</p>

    <p><label for="txtMessage">Your message:</label><br />
    <textarea title="Enter your message" name="txtMessage"></textarea></p>
   
    <p><label title="Send your message">
    <input type="submit" value="Send" /></label></p>
   
</form><?php

/**
* Create the table in your MySQL database:
*
* CREATE TABLE guests (
*   id int(10) NOT NULL auto_increment,
*   name varchar(50) NOT NULL,
*   message varchar(255) NOT NULL,
*   date timestamp(14) NOT NULL,
*   PRIMARY KEY (id)
* )
*
* Change the database login settings to your own
*
* The script is now ready to run
*/

// Change these to your own database settings

mysql_connect($host, $user, $pass) OR die ("Could not connect to the server.");
mysql_select_db($db) OR die("Could not connect to the database.");
     
$name = stripslashes($_POST['txtName']);
$message = stripslashes($_POST['txtMessage']);
$rate = stripslashes($_POST['rate']);

if (!isset($_POST['txtName'])) {

    $query = "SELECT id, name, rate, message, DATE_FORMAT(date, '%D %M, %Y at %H:%i') as newdate FROM guests ORDER BY id DESC";
    $result = mysql_query($query);
   
    while ($row = mysql_fetch_object($result)) {

?>

<p><strong><?php echo $row->message; ?><br />
<?php echo $row->rate; ?></strong>
<br />Posted by <?php echo $row->name; ?> on <?php echo $row->newdate; ?></p>

<?php
       
    }
   
?>

<p>Post a message</p>



<?php

}

else {

    // Adds the new entry to the database
    $query = "INSERT INTO guests SET message='$message', name='$name', date=NOW(), rate='$rate'";
    $result = mysql_query($query);

    // Takes us back to the entries
    $ref = $_SERVER['HTTP_REFERER'];
    header ("Location: $ref");
}

?>




THANK YOU FOR ANY HELP.

#2 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 26 October 2006 - 09:22 PM

this is supposed to be a bandaid but try puting this at the very beginning...

ob_start();


#3 bryanptcs

bryanptcs
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 27 October 2006 - 01:13 PM

that didn't do anything

#4 bryanptcs

bryanptcs
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 27 October 2006 - 01:20 PM

my bad, i didn't have it in the right place.  Thanks.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users