Jump to content


This topic is now archived and is closed to further replies.


PHP Guestbook Error Code

Recommended Posts

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

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

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


<p>Post a message</p>



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");



Share this post

Link to post
Share on other sites
this is supposed to be a bandaid but try puting this at the very beginning...


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.