Jump to content

calendar post


dare87

Recommended Posts

I am trying to write somthing that will pull all of the calendar events of the current month and beyond. The problem I am having is that it will not post the events for the next year. Here is what I have, Thanks for your help

 

<?php
// This will post the current calendar events.

$currentday = (int) date("d", time());
$currentmonth = (int) date("m", time());
$currentyear = (int) date("Y", time());

// Connect to the database.
require_once('mysql_connect.php');

$query = "SELECT title, m, d, y, time FROM calendar WHERE m >= $currentmonth and y >= $currentyear ORDER BY m, d, y";
$results = mysql_query($query);

if ($results)
{
// Start the table.
echo '<h3 style="color: #af410d">Upcoming Events</h3>
<table>';

// Insert the results.
while ($row = mysql_fetch_array($results, MYSQL_ASSOC))
{
	echo '
	<tr><td width="15px"> </td>
	<td><i>' . $row['m'] . '/' . $row['d'] . '/' . $row['y'] . '</i> - ' . $row['title'] . ' <i>' . $row['time'] . '</i></td>';
}

// Close the table.
echo '</table>';

// Free up the resources.
mysql_free_result ($results);
}
else
echo 'There are no calendar events';
?>

Link to comment
https://forums.phpfreaks.com/topic/134103-calendar-post/
Share on other sites

This is how I gather the info, how would I change it to be yyyy-mm-dd?

 

<?php
			if (isset($_POST['submit'])) // The form has been submitted.
			{
				// Initialize an error array to contain any error messages.
				$errors = array();

				// Check for a title.
				if (!empty($_REQUEST['title']))
					$title = $_REQUEST['title'];
				else
					$errors[] = 'Please enter a title.';

				// Check for an article.
				if (!empty($_REQUEST['m']))
					$m = $_REQUEST['m'];
				else
					$errors[] = 'Please enter a Month.';

				// Check for an article.
				if (!empty($_REQUEST['d']))
					$d = $_REQUEST['d'];
				else
					$errors[] = 'Please enter a Day.';

				// Check for an article.
				if (!empty($_REQUEST['y']))
					$y = $_REQUEST['y'];
				else
					$errors[] = 'Please enter a Year.';

				// Check for an article.
				if (!empty($_REQUEST['time']))
					$time = $_REQUEST['time'];


				// Save the author's information.
				$author = $_SESSION['firstName'] . ' ' . $_SESSION['lastName'];
				$authorId = $_SESSION['userId'];


				// Submit the article.
				if (empty($errors))
				{
					// Connect to the database.
					require_once('mysql_connect.php');

					$query = "INSERT INTO calendar SET title='$title', m='$m', d='$d', y='$y', time='$time', user_id=$authorId, author='$author', date_written=NOW()";
					$results = @mysql_query($query);

					if ($results)
						echo 'Thank you. Your celendar even has been posted.';
					else
						echo 'Your calendar event could not be added to the database.';
				}
				else
					foreach ($errors as $msg)
						echo " - $msg<br/>\n"; 
			}
			?>
                <form name="composeNews" action="calendar_compose.php" method="post">
				<table align="center" width="100%" border="0" cellpadding="1" cellspacing="0">
				<tr>
					<td colspan="2"><b>Compose Calendar Event</b></td>
				</tr>
				<tr>
					<td>Title:</td>
					<td><input type="text" class="required" name="title" id="focus" size="40" value="<?php echo $title; ?>" maxlength="50"></td>
				</tr>
				<tr>
					<td>Date:</td>
					<td><select name="m" class="required">
                            <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>
					<select name="d" class="required">
                            <option value="01">1</option>
						<option value="02">2</option>
						<option value="03">3</option>
						<option value="04">4</option>
						<option value="05">5</option>
						<option value="06">6</option>
						<option value="07">7</option>
						<option value="08">8</option>
						<option value="09">9</option>
						<option value="10">10</option>
						<option value="11">11</option>
						<option value="12">12</option>
						<option value="13">13</option>
						<option value="14">14</option>
						<option value="15">15</option>
						<option value="16">16</option>
						<option value="17">17</option>
						<option value="18">18</option>
						<option value="19">19</option>
						<option value="20">20</option>
						<option value="21">21</option>
						<option value="22">22</option>
						<option value="23">23</option>
						<option value="24">24</option>
						<option value="25">25</option>
						<option value="26">26</option>
						<option value="27">27</option>
						<option value="28">28</option>
						<option value="29">29</option>
						<option value="30">30</option>
						<option value="31">31</option>
					</select>

					<select name="y" class="required">
					<?php
						$currentyear = (int) date("Y", time());
						for ($y = ($currentyear); $y <= ($currentyear + 4); $y++)
						{
					?>
                                <option value="<?php echo $y; ?>"><?php echo $y; ?></option>
					<?php
						}
					?>
					</select></td>
				</tr>
                    <tr>
					<td>Time:</td>
					<td><input type="text" name="time" id="focus" size="40" value="<?php echo $time; ?>" maxlength="50"> - <i>xx:xx AM/PM</i></td>
				</tr>
				<tr>
					<td> </td>
					<td><input type="submit" class="button" name="submit" value="Submit"></td>
				</tr>
				<tr>
					<td> </td>
					<td class="smallText">* Highlighted forms designate required fields.</td>
				</tr>
				</table>
			</form>

 

I've tried multiple ways of going it and I can't seem to find the answer

Link to comment
https://forums.phpfreaks.com/topic/134103-calendar-post/#findComment-698099
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.