aquatradehub Posted April 29, 2014 Share Posted April 29, 2014 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 Quote Link to comment Share on other sites More sharing options...
aquatradehub Posted April 29, 2014 Author Share Posted April 29, 2014 Syntax error here NOW()) ??? Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 29, 2014 Share Posted April 29, 2014 this thread seems to be a variation of the same code and query error in your previous thread. i recommend you revisit that thread and read my reply in it concerning the sql syntax error you are getting. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.