Form Submitting Incorrect Information to MySQL Database

Posted by ThatMacLad on Stack Overflow See other posts from Stack Overflow or by ThatMacLad
Published on 2010-05-01T16:57:39Z Indexed on 2010/05/01 17:07 UTC
Read the original article Hit count: 170

Filed under:
|
|

I've created a form that submits data to a MySQL database but the Date, Time, Year and Month fields constantly revert to the exact same date (1st January 1970) despite the fact that when I submit the information to the database the form displays the current date, time etc to me. I've already set it so that the time and date fields automatically display the current time and date. Could someone please help me with this.

Form:

<html>

<head>
<title>Blog | New Post</title>
<link rel="stylesheet" href="css/newposts.css" type="text/css" />
</head>

<body>
<div class="new-form">
<div class="header">
<a href="edit.php"><img src="images/edit-home-button.png"></a>
</div>
<div class="form-bg">
<?php
if (isset($_POST['submit'])) {

    $month = htmlspecialchars(strip_tags($_POST['month']));
    $date = htmlspecialchars(strip_tags($_POST['date']));
    $year = htmlspecialchars(strip_tags($_POST['year']));
    $time = htmlspecialchars(strip_tags($_POST['time']));
    $title = htmlspecialchars(strip_tags($_POST['title']));
    $entry = $_POST['entry'];

    $timestamp = strtotime($month . " " . $date . " " . $year . " " . $time);

    $entry = nl2br($entry);

    if (!get_magic_quotes_gpc()) {
        $title = addslashes($title);
        $entry = addslashes($entry);
    }

    mysql_connect ('localhost', 'root', 'root') ;
    mysql_select_db ('tmlblog');

$sql = "INSERT INTO php_blog (timestamp,title,entry) VALUES ('$timestamp','$title','$entry')";

    $result = mysql_query($sql) or print("Can't insert into table php_blog.<br />" . $sql . "<br />" . mysql_error());

    if ($result != false) {
        print "<p class=\"success\">Your entry has successfully been entered into the blog. </p>";
    }

    mysql_close();
}
?>

<?php
$current_month = date("F");
$current_date = date("d");
$current_year = date("Y");
$current_time = date("H:i");
?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<input class="field" type="text" name="date" id="date" size="2" value="<?php echo $current_month; ?>" />
<input class="field" type="text" name="date" id="date" size="2" value="<?php echo $current_date; ?>" />

<input class="field" type="text" name="date" id="date" size="2" value="<?php echo $current_year; ?>" />

<input type="text" name="time" id="time" size="5"value="<?php echo $current_time; ?>" />

<input class="field2" type="text" id="title" value="Title Goes Here." name="title" size="40" />

<textarea class="textarea" cols="80" rows="20" name="entry" id="entry" class="field2"></textarea>

<input class="field" type="submit" name="submit" id="submit" value="Submit">

</form>
</div>
</div>
 </div>
 <div class="bottom"></div>
</body>

</html>

© Stack Overflow or respective owner

Related posts about mysql

Related posts about php