Calendar/Form Data Help
Posted: Tue Apr 20, 2010 3:22 am
I've got a calendar script that I've started modifying, a book tutorial I bought and went through but I did the tutorial and got the script working W00T go me, anyhow I am starting to add some features, what I want is to be able to add events to the calendar weekly for say x weeks, on odd numbered days for x weeks, or even number days for x weeks. I would also like to include a monthly event add by either number of days of week in the month with a default of no even if it doesn't exist, and of course monthly event add by day the number and no even if the number doesn't exist in the next month. Anyhow my problem as I start this is actually really simple, and I am a newbie, and sometimes things just don't set right in my head (although I am a Java Programmer) With all the information I've given, will I have to create yet another PHP page to get all the data I want to pass to the add event, or can I manipulate the data based on forms already on the site. I really don't know how to go about it, but here's what I was thinking so far I'm just not quite sure how I should be writing in the values and checking for them... I know it's generally a rule not to write the code for an "asker," and I ask you NOT to. I wouldn't mind an example of form data extraction. I put "STOP!" where I was changing a bit, I've done a few searches and I haven't found quite what I am looking for. again the code I'm playing with so far is:
Code: Select all
<html>
<head>
<title>Show/Add Events</title>
<head>
<body>
<h1>Show/Add Events</h1>
<?php
$mysqli = mysqli_connect("localhost", "root", "R3dwall", "calendardb");
//add any new event
if ($_POST) {
$m = $_POST["m"];
$d = $_POST["d"];
$y = $_POST["y"];
$event_date = $y."-".$m."-".$d." ".$_POST["event_time_hh"].":".$_POST["event_time_mm"].":00";
$insEvent_sql = "INSERT INTO calendar_events (event_title, event_shortdesc, event_start) VALUES('".$_POST["event_title"]."', '".$_POST["event_shortdesc"]."', '$event_date')";
$insEvent_res = mysqli_query($mysqli, $insEvent_sql) or die(mysqli_error($mysqli));
} else {
$m = $_GET["m"];
$d = $_GET["d"];
$y = $_GET["y"];
}
//show events for this day
$getEvent_sql = "SELECT event_title, event_shortdesc, date_format(event_start, '%l:%i %p') as fmt_date FROM calendar_events WHERE month(event_start) = '".$m."' AND dayofmonth(event_start) = '".$d."' AND year(event_start) = '".$y."' ORDER BY event_start";
$getEvent_res = mysqli_query($mysqli, $getEvent_sql) or die(mysqli_error($mysqli));
if (mysqli_num_rows($getEvent_res) > 0) {
$event_txt = "<ul>";
while ($ev = @mysqli_fetch_array($getEvent_res)) {
$event_title = stripslashes($ev["event_title"]);
$event_shortdesc = stripslashes($ev["event_shortdesc"]);
$fmt_date = $ev["fmt_date"];
$event_txt .= "<li><strong>".$fmt_date."</strong>: ".$event_title."<br/>".$event_shortdesc."</li>";
}
$event_txt .= "</ul>";
mysqli_free_result($getEvent_res);
} else {
$event_txt = "";
}
mysqli_close($mysqli);
if ($event_txt != "") {
echo "<p><strong>Today's Events:</strong></p>
$event_txt
<hr/>";
}
// show form for adding an event
echo "
<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">
<p><strong>Would you like to add an event?</strong><br/>
Complete the form below and press the submit button to add the event and refresh this window.</p>
<p><strong>Event Title:</strong><br/>
<input type=\"text\" name=\"event_title\" size=\"25\" maxlength=\"25\"/>
<p><strong>Event Description:</strong><br/>
<input type=\"text\" name=\"event_shortdesc\" size=\"25\" maxlength=\"255\"/>
<p><strong>Event Time (hh:mm):</strong><br/>
<select name=\"event_time_hh\">";
for ($x=1; $x <= 24; $x++) {
echo "<option value=\"$x\">$x</option>";
}
echo "</select> :
<select name=\"event_time_mm\">
<option value=\"00\">00</option>
<option value=\"15\">15</option>
<option value=\"30\">30</option>
<option value=\"45\">45</option>
</select>
<input type=\"hidden\" name=\"m\" value=\"".$m."\">
<input type=\"hidden\" name=\"d\" value=\"".$d."\">
<input type=\"hidden\" name=\"y\" value=\"".$y."\">
// STOP!
// This is where I am working for the above post:
<br/><br/>
<label for=\"once\"><input type=\"radio\"
name=\"days\" id=\"once\" value=\"0\" CHECKED/> One Time</label>
<label for=\"odd\"><input type=\"radio\"
name=\"days\" id=\"odd\" value=\"1\" /> Odd Days</label>
<label for=\"even\"><input type=\"radio\"
name=\"days\" id=\"even\" value=\"2\" /> Even Days</label>
<label for=\"weekly\"><input type=\"radio\"
name=\"days\" id=\"weekly\" value=\"3\" /> Weekly</label>
<br/><br/>
<input type=\"submit\" name=\"submit\" value=\"Add Event\">
</form>";
?>
</body>
</html>