Page 1 of 1

data entry form displays incorrectly

Posted: Fri Dec 31, 2010 9:41 pm
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>

Re: data entry form displays incorrectly

Posted: Fri Dec 31, 2010 11:25 pm
by anantha
remove the last ?> which you have..

Re: data entry form displays incorrectly

Posted: Sat Jan 01, 2011 3:19 pm
by drayarms
thank you all for your vigillance. i just wasn't vigilant enough.