Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2012
    Posts
    99
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Error due to NOW()

    Hi, I have this form which should write the details to the database and display the results afterwards, enabling the user to create a diary.

    Here is the code

    PHP Code:
    <?php 
    include 'core/init.php';
    protect_page();
    include 
    'includes/overall/header.php'

        
    $user_id $_POST['user_id'];
        
    $username $_POST['username'];
        
    $diary_entry $_POST['diary_entry'];

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

    ?>

        <form action="" method="POST">
        <input type="hidden" name="user_id" value="<?php echo $user_data['user_id']; ?>"></li>
        <input type="hidden" name="username" value="<?php echo $user_data['username']; ?>"></li>
        <ul>
            <li>
                Diary Entry*:<br>
                <textarea name="diary_entry"></textarea>
            </li>
            <li><input type="submit" value="Submit"></li>
            </ul>
        </form>
     
    <?php
        $result 
    mysql_query("SELECT * FROM diary WHERE username = $username");

    while(
    $row mysql_fetch_array($result))
      {
      echo 
    "<ul>";
      echo 
    "<li>" 'Entry by' $row['username'] . "</li>";
      echo 
    "<li>" 'Date of Entry' $row['entry_date'] . "</li>";
      echo 
    "<li>" 'Diary Entry' $row['diary_entry'] . "</li>";
      echo 
    "</ul>";
      }
      
    ?> 

    <?php 

    include 'includes/overall/footer.php'?>
    But I get this error

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' , NOW())' at line 1

    I cant work out whats wrong Please help!

  • #2
    Regular Coder
    Join Date
    Jun 2009
    Posts
    141
    Thanks
    3
    Thanked 20 Times in 20 Posts
    INSERT INTO diary (user_id, username, diary_entry, datetime) VALUES('{$_SESSION['user_id']}', '{$_SESSION['username']}', '$diary_entry', NOW())


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •