Jump to content

PHP Guestbook Error Code


bryanptcs

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">
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.