TLN_CANADA
asked on
Default value not added to DB
Hi all,
I have a form input box with it's value set like this:
If the user does not change the title (from Journal Optional) I do not want "journal optional" to be stored in the db as the name but want this field left as blank if it has been untouched.
Here is where I add it to the DB, could someone tell me how to make this change?
Thanks,
D
I have a form input box with it's value set like this:
input type = "text" value="Journal Title (Optional)" onFocus="this.value=''" name = "Journal_Title"
If the user does not change the title (from Journal Optional) I do not want "journal optional" to be stored in the db as the name but want this field left as blank if it has been untouched.
Here is where I add it to the DB, could someone tell me how to make this change?
$title = mysql_real_escape_string($_POST['Journal_Title']);
$content = mysql_real_escape_string($_POST['Journal_Content']);
if ( strlen($title) > 1 && strlen($content) > 1 )
{
// Inserting data in the database
if ( mysql_query("INSERT INTO journal_table (user_id, entry_title, entry_text) VALUES('$username','$title','$content')") )
{
$_SESSION[$outcome] = "Journal successfully added!";
?>
Thanks,
D
ASKER
Thanks, here is what I have on the page now:
I want to allow this field to be blank when I enter it into the database if the user has not put anything in there. At the moment it is asking for a value or else it won't enter the record.
Thank you,
D
$username = Phpfox::getUserBy('full_name');
$title = mysql_real_escape_string($_POST['Journal_Title']);
if ($title == 'Journal Title (Optional)' ) { $title = ''; }
$content = mysql_real_escape_string($_POST['Journal_Content']);
if ( strlen($title) > 1 && strlen($content) > 1 )
{
// Inserting data in the database
if ( mysql_query("INSERT INTO journal_table (user_id, entry_title, entry_text) VALUES('$username','$title','$content')") )
{
$_SESSION[$outcome] = "Journal successfully added!";
?>
<script type = "text/javascript">location.href = "http://www.clearthemirror.com/searchjournal.php";</script>
<?php
}
else
{
$_SESSION[$outcome] = "Something unexpected went wrong! Please try again later!";
}
}
else
{
$_SESSION[$outcome] = "The entry or the title was too short!";
}
}
?>
I want to allow this field to be blank when I enter it into the database if the user has not put anything in there. At the moment it is asking for a value or else it won't enter the record.
Thank you,
D
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window