PDA

View Full Version : PHP & Print message for database entry


urbanrays
11-28-2010, 03:38 PM
Hi

Just having a play with database's and php and reading through PHP third edition

Now I have done this code from the book


<?php
if (isset($_POST['submitted'])) {
$dbc = mysql_connect('yeah', 'im', 'stupid');
mysql_select_db('tester');
$problem = FALSE;
if (!empty($_POST['title']) &&
!empty($_POST['entry'])){
$title = trim($_POST['title']);
$entry = trim($_POST['entry']);
} else {
print '<p>You need to write something</p>';
$problem = TRUE;
}
if (!$problem) {
$query = "INSERT INTO enteries
(entry_id, title, entry, date_
entered) VALUES (0, '$title',
'$entry', NOW())";

if (@mysql_query($query)) {
print '<p>Its in</p>';
} else {
print '<p>It wont go in</p>';

}

}
mysql_close();
}
?>
<form action="entry.php" method="post">
<p>Entry Title: <input type="text" name="title" size="40" maxsize="100"/></p>
<p>Entry Text: <textarea name="entry" cols="40" rows="5"></textarea></p>
<input type="submit" name="submit" value="POST THIS"/>
<input type="hidden" nam="submitted" value="true"/>
</form>


Everything seems to be working no errors etc it just isnt printing
the messages ie

print '<p>You need to write something</p>';

print '<p>Its in</p>';

print '<p>It wont go in</p>';

I have looked over and over it again and now my eyes hurt.

Can anyone tell me why its not printing these messages

Thanks in advance

urbanrays
11-28-2010, 06:56 PM
<input type="hidden" nam="submitted" value="true"/>


Instantly spotted the mistake after leaving it for a couple of hours, missing a vital e in "name

davidj
11-30-2010, 10:31 AM
that would do it

Its excellent that your learning to code

Respect