Link to home
Start Free TrialLog in
Avatar of TLN_CANADA
TLN_CANADAFlag for Afghanistan

asked on

Default value not added to DB

Hi all,

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"

Open in new window


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!";
			?>

Open in new window


Thanks,

D
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

you have to test that case, then:
$title = mysql_real_escape_string($_POST['Journal_Title']);
if ($title == 'Journal Title (Optional)' ) { $title = ''; }

Open in new window

Avatar of TLN_CANADA

ASKER

Thanks, here is what I have on the page now:

	$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!";
	}

}
?>

Open in new window


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
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial