data entry form displays incorrectly

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
drayarms
Forum Contributor
Posts: 134
Joined: Fri Dec 31, 2010 5:11 pm

data entry form displays incorrectly

Post by drayarms »

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.






<html>

<head>
<title> post entries </title>


<body>

<div id="main_center" class="" style="float:left; height:100%; width:59%; border:0px solid #c0c0c0;"> <!--opens main center-->


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

</body>
</html>
anantha
Forum Commoner
Posts: 59
Joined: Thu Dec 23, 2010 7:38 pm

Re: data entry form displays incorrectly

Post by anantha »

remove the last ?> which you have..
drayarms
Forum Contributor
Posts: 134
Joined: Fri Dec 31, 2010 5:11 pm

Re: data entry form displays incorrectly

Post by drayarms »

thank you all for your vigillance. i just wasn't vigilant enough.
Post Reply