data entry form displays incorrectly!

I obtained the following code from a book by Larry Ullman (with a few modificatiosn), on inserting data into a database table. The resulting page is supposed to display the data entry form and execute the insert query. It does so alright, but the php closing tag ‘?>’ unscrupulously gets printed out at the end of the form. What should I change about my code to get rid of that tag? Answers and ideas will be greatly appreciated.

post entries
               <?php

             
                 //address error handling

                 ini_set ('display_errors', 1);
                 error_reporting (E_ALL & ~E_NOTICE);

                 if (isset ($_POST['submit'])) { //handle the form.
            
                    //connect to database
                    require_once("config.php");
                    

                 //define the query.
                 $query = "INSERT INTO blogs (blog_id, title, entry) VALUES (0, '{$_POST['title']}', '{$_POST['entry']}')";
                          "INSERT INTO entrydates (entrydate_id, entrydate) VALUES (0, NOW())";

                 //execute the query
                 if (@mysql_query ($query)) {
                      print '<p> Your entry has been submitted. Thank you!</p>';
                      print '<p> <h3><a style="text-decoration:none" href="blogs.php">Return to hahap tok</a></h3></p>';
                 } else {
                      print "<p>Could not add the entry because: <b>" . mysql_error() . 
                      "</b>. The query was $query.</p>";
                 }
                 mysql_close();
               }

               
              
                //Display the form.
                
                 ?>
              
                   
                 
                   
                    
                      <p><h2>Please, Add Your Contribution to Half Tok Library!</h2></p>

                      <p>
                        
                          <form action ="blog_entries.php" method="post">
                            <p>Title:       <input type="text" name =title" size="40" maxsize="100" /></p>
                            <p>Explanation: <textarea name= "entry" cols="40" rows="5"></textarea></p>
                            <!-- It is good practice to use the same name from inputs as the corresponding column names in databse, avoiding confusion.--> 
                                            <input type="submit" name="submit" value="Post your Entry!"> 

                          </form>
                       

                      </p>






                ?>


           </div> <!-- closes main center--> 

If you look closely at your code you will see two PHP closing tags in your code: one after the line // Display the form and the other one after the

tag at the end of the script. Remove the one at the end of the script and you should be fine.

thanks for your vigilance. i just wasn’t vigilant enough.

Sponsor our Newsletter | Privacy Policy | Terms of Service