logixxxx Posted April 6, 2007 Share Posted April 6, 2007 Hello fellow users. I'm using the basic PHP event calendar tutorial that is on this website, and I made a form to add the events. The problem is that the date isn't posting right into the MySQL. For the date it says: '0000-00-00' instead of what I inputed. <?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'])); $desc = $_POST['desc']; $timestamp = strtotime('$date'); $desc = nl2br($desc); if (!get_magic_quotes_gpc()) { $title = addslashes($title); $desc = addslashes($desc); } db(); $sql = "INSERT INTO " . $mysql["db_prefix"] . "calevents VALUES ('', '$timestamp', '$title', '$desc')"; Quote Link to comment Share on other sites More sharing options...
$cripts Posted April 6, 2007 Share Posted April 6, 2007 try this $timestamp = mktime($hour,$minute,$second,$month,$day,$year); Quote Link to comment Share on other sites More sharing options...
logixxxx Posted April 6, 2007 Author Share Posted April 6, 2007 It doesn't seem to wrok Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 6, 2007 Share Posted April 6, 2007 This line: <?php $timestamp = strtotime('$date'); ?> should be <?php $timestamp = strtotime($date); ?> Ken Quote Link to comment Share on other sites More sharing options...
logixxxx Posted April 6, 2007 Author Share Posted April 6, 2007 Hey Ken... That didn't work :-( Here's the entire page code: <?php include("../inc/include.php"); ?> <?php include("password_protect.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="stylesheet" href="acpstyle.css" type="text/css"/> <title>Horizon Control Panel</title> <style type="text/css"> <!-- .style1 { font-size: 16px; font-weight: bold; } .style3 {font-size: 14px} --> </style> <script language="javascript" type="text/javascript" src="../inc/tiny_mce/tiny_mce.js"></script> <script language="javascript" type="text/javascript"> tinyMCE.init({ mode : "textareas", plugins : "emotions, style", theme_advanced_buttons3_add : "emotions, styleprops", }); </script> </head> <body background="img/background.gif" bgcolor="#259ce3" style="background-repeat:repeat-x"> <div id="wrapper"> <div align="center"><img src="img/top.gif" width="100%"><br /><img src="img/logo.gif" /> </div><br /> <br /> <div id="navigation"> <?php require("acp_nav.php"); ?> </div><br /><br /><div id="main"> <center><?php $current_month = date("F"); $current_date = date("d"); $current_year = date("Y"); $current_time = date("H:i"); ?> <form name="createArticle" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <p><strong><label for="month">Date: </label></strong> <select name="month" id="month"> <option value="<?php echo $current_month; ?>"><?php echo $current_month; ?></option> <option value="01">January</option> <option value="02">February</option> <option value="03">March</option> <option value="04">April</option> <option value="05">May</option> <option value="06">June</option> <option value="07">July</option> <option value="08">August</option> <option value="09">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> <input type="text" name="date" id="date" size="2" value="<?php echo $current_date; ?>" /> <select name="year" id="year"> <option value="<?php echo $current_year; ?>"><?php echo $current_year; ?></option> <option value="2007">2007</option> <option value="2008">2008</option> <option value="2009">2008</option> <option value="2010">2010</option> </select> <strong><label for="time">Time: </label></strong> <input type="text" name="time" id="time" size="5" value="<?php echo $current_time; ?>" /></p> <p><strong><label for="title">Event: </label></strong> <input type="text" name="title" name="title" size="40" /></p> <p><textarea cols="80" rows="20" name="desc" id="desc"></textarea></p> <p><input type="submit" name="submit" id="submit" value="Submit"></p> </form> <?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'])); $desc = $_POST['desc']; $timestamp = strtotime($date); $desc = nl2br($desc); if (!get_magic_quotes_gpc()) { $title = addslashes($title); $desc = addslashes($desc); } db(); $sql = "INSERT INTO " . $mysql["db_prefix"] . "calevents VALUES ('', '$timestamp', '$title', '$desc')"; $result = mysql_query($sql) or print("Can't insert into table " . $mysql["db_prefix"] . "main<br />" . $sql . "<br />" . mysql_error()); if ($result != false) { print " <div style='width: 98%; background-color: #FFCACA; font-weight: bold; font-family: Verdana; font-size: 14px; padding: 5px; border: 1px dashed #FF0000;' align='center'><div align='center'>Your event has successfully been added!<br /><a href='index.php'>Admin Home</a> or <a href='../index.php'>View Entry</a></div></div> "; } mysql_close(); } ?></center> </div> <br /> <br /> <center> Powered by <a href="http://www.itsdaybreak.com/horizon">Horizon Blogging Software</a> <?php echo getVersion();?><br /> Copyright © 2006 - <?php echo date("Y");?> <a href="http://www.itsdaybreak.com">Daybreak Studios</a> <img src="img/bottom.gif" width="100%"></center></div> </body> </html> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 7, 2007 Share Posted April 7, 2007 Your problem here is that the date you want to insert into the database is coming from multiple fields in your form, not just the one you're trying to store. <?php $month = htmlspecialchars(strip_tags($_POST['month'])); $date = htmlspecialchars(strip_tags($_POST['date'])); $year = htmlspecialchars(strip_tags($_POST['year'])); $time = htmlspecialchars(strip_tags($_POST['time'])); ?> Instead of doing <?php $timestamp = strtotime($date); ?> do <?php $timestamp = strtotime($year . '-' . $month . '-' . $date . ' ' . $time); ?> Ken 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.