bryanptcs Posted October 26, 2006 Share Posted October 26, 2006 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 137The 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 settingsmysql_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. Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted October 26, 2006 Share Posted October 26, 2006 this is supposed to be a bandaid but try puting this at the very beginning... [code]ob_start();[/code] Quote Link to comment Share on other sites More sharing options...
bryanptcs Posted October 27, 2006 Author Share Posted October 27, 2006 that didn't do anything Quote Link to comment Share on other sites More sharing options...
bryanptcs Posted October 27, 2006 Author Share Posted October 27, 2006 my bad, i didn't have it in the right place. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.