Jump to content

Form is not displayed


aquatradehub

Recommended Posts

Hi, I have a form and the processing code on the same page, but the Heading is displayed, but the form is not. I have other similar forms that work fine, but i cant seem to work out was is wrong here.

 

Here is the function that writes the info to the mySQL DB.

function diary_entry($user_id, $diary_data) {

mysql_query("INSERT INTO diary
        (user_id, username, diary_entry, datetime) VALUES({$_SESSION['user_id']}, {$_SESSION['username']}, $diary_entry, NOW()) ") 
        or die(mysql_error());
}

And here is the page

<?php
include 'core/init.php';
include 'includes/overall/header.php';


if (empty($_POST) === false) {
	$required_fields = array('diary_entry');
	foreach($_POST as $key=>$value) {
		if (empty($value) && in_array($key, $required_fields) === true) {
			$errors[] = 'Fields marked with an asterisk are required';
			break 1;
		}
	}
	
	if (empty($errors) === true) {
		if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) {
			$errors[] = 'A valid email address is required';
		}
	if(empty($diary_entry) === false) {
		$errors[] = 'Please enter a entry in your diary.';
		}
	}
}

?>
<h1>My Diary</h1>

<?php
if (isset($_GET['success']) === true && empty($_GET['success']) === true) {
	$username = $user_data['username'];
	echo 'Your message has been sent!';?>
	<br>
	<br>
	<a href="index.php">Please click here to return to your diary</a>
<?php
    
	header( "Refresh:5; url=$username", true, 303);
} else {
	if (empty($_POST) === false && empty($errors) === true) {
		
		$diary_data = array(
	     	'user_id' => $user_data['user_id'],
			'username' 	=> $user_data['username'],
			'diary_entry' 	=> $_POST['diary_entry'],
			'datetime' 		=> $_POST['datetime']
			);
		
		
		diary_entry($diary_data, $user_id);
		header('Location: fish_diary.php?success');
		exit();
		
	} else if (empty($errors) === false) {
		echo output_errors($errors);
	}
	?>

	
	<form action="" method="POST">
	<input type="hidden" name="user_id" value="<?php echo $user_data['user_id']; ?>">
    <input type="hidden" name="username" value="<?php echo $user_data['username']; ?>">
	<input type="hidden" name="datetime" value="<?php CURDATE(); ?>">

	<ul>
		<li>
			Diary Entry*:<br>
			<textarea name="diary_entry"></textarea>
		</li>
		<li><input type="submit" value="Submit"></li>
		</ul>
	</form>

<?php
}
include 'includes/overall/footer.php';
?>

Can anyone see where I have gone wrong?

 

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.