matt.sisto Posted March 11, 2009 Share Posted March 11, 2009 Hello all, I am relatively new to php, I have been trying to get this bit of code to work but it just shows a blank page? It works fine until I try to add the popup window for event.php. If any one can see any flawes in my code I would appreciate the help greatly. calendar.php: <?php require "dbconn2.php"; define ("ADAY", (60*60*24)); if ((!isset($_POST["month"])) || (!isset($_POST["year"]))) { $nowArray = getdate(); $month = $nowArray ["mon"]; $year = $nowArray ["year"]; } else { $month = $_POST["month"]; $year = $_POST["year"]; } $start = mktime (12, 0, 0, $month, $year); $firstDayArray = getdate ($start); ?> <!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> <meta http-equiv="Content-Type" content="text/xml; charset=UTF-8" /> <title><?php echo "Calendar: ".$firstDayArray["month"].",".$firstDayArray["year"] ?> </title> <script type="text/javascript"> function eventWindow(url) { event_popupWin = window.open(url, 'event','resizable = yes, scrollbars = yes, toolbar = no, width = 400, height = 400' ); event_popupWin.opener = self; } </script> </head> <body> <h1>Select Month/Year Combination</h1> <form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>"> <select name="month"> <?php $months = Array ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); for ($x = 1; $x <= count($months); $x++) { echo "<option value =\"$x\""; if ($x == $month) { echo " selected"; } } ?> </select> <select name="year"> <?php for ($x = 1980; $x = 2010; $x++) { echo "<option"; if ($x == $year) { echo " selected"; } echo ">$x</option>"; } ?> </select> </form> <br /> <?php $days = Array ("Mon","Tue","Wed","Thu","Fri","Sat","Sun"); echo "<table border=\"1\" cellpadding=\"5\"><tr>\n"; foreach ($days as $day) { echo "<td style=\"background-color: #CCCCCC; text-align: center; width: 14%\"><strong>$day</strong></td>\n"; } for ($count = 0; $count < (6*7); $count++) { $dayArray = getdate ($start); if (($count % 7) == 0) { if($dayArray["mon"] != $month) { break; } else { echo "</tr><tr>\n"; } } if ($count < $firstDayArroay["wday"] || $dayArray["mon"] != $month) { echo "<td> </td>\n"; } else { $chkEvent_sql = "SELECT event_title FROM calendar_events WHERE month (event_start) = '".$month."' AND dayofmonth (event_start) = '".$dayArray["mday"]."' AND year(event_start) = '".$year."' ORDER BY event_start"; $chkEvent_res = mysqli_query ($mysqli, $chkEvent_sql) or die (mysqli_error($mysqli)); if (mysqli_num_rows(%chkEvent_res) > 0) { $event_title = "<br />"; while ($ev = mysqli_fetch_array(chkEvent_res)) { $event_title = stripslashes ($ev["event_title"])."<br />"; } mysqli_free_result(chkEvent_res); } else { $event_title = ""; } echo "<td valign=\"top\"><a href=\"javascript:eventWindow ('event.php? m=".$month."d=".$dayArray["mday"]."&y=$year');\">".$dayArray["mday"]. "</a><br />".$event_title."</td>\n"; unset($event_title); $start += ADAY; } } echo "</tr></table>"; ?> </body> </html> event.php: <?php require "dbconn.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> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Show/Add event</title> </head> <body> <h1>Show/Add Event</h1> <?php //add a 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 selected day $getEvent_sql = "SELECT event_title, event_shortdesc, date_format(event_start, '%1:%i %p') as fmt_date FROM calendar_events WHERE month(event_start) = '".$m."' AD dayofmonth(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 = @myslqi_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 = ""; } if ($event_txt != "") { echo "<p><strong>Todays Events: </strong></p> $event_txt <hr />"; } // show the form for ading an event echo " <form method=\"post\" action\"".$_SERVER["PHP_SELF"]."\"> <p><strong>Woukd You Like To Add A New Event?</strong><br /> Complete the form belowm then submit it to add a new event and refresh the 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 = \"250\"/> <p><strong>Event Time(hh:mm):</strong><br /> <select name=\"event_time_hh\">"; for ($x = 1; $z <= 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."\"> <br /><br /> <input type=\"submit\" name=\"Add\" value=\"Add Event\"> </form>"; ?> </body> </html> please please help, thanks and regs. Link to comment https://forums.phpfreaks.com/topic/148905-calender-with-event-adder/ Share on other sites More sharing options...
MiCR0 Posted March 11, 2009 Share Posted March 11, 2009 <?php for ($x = 1980; $x = 2010; $x++) // bug $x = 2010; { echo "<option"; if ($x == $year) { echo " selected"; } echo ">$x</option>"; } ?> for ($x = 1; $z <= 24; $x++) // $z <= 24; I think this should be $x { echo "<option value=\"$x\">$x</option>"; } // vulnerabilitys <form method=\"post\" action\"".htmlentities($_SERVER["PHP_SELF"])."\"> $m = $_POST["m"]; $d = $_POST["d"]; $y = $_POST["y"]; // I think the above are int's so set them like this $m = intval($_POST['m']); $m = (int) $m; $m = mysqli_real_escape_string($m) Link to comment https://forums.phpfreaks.com/topic/148905-calender-with-event-adder/#findComment-781893 Share on other sites More sharing options...
matt.sisto Posted March 12, 2009 Author Share Posted March 12, 2009 Thanks a lot for pointing out those bugs, its so easy to miss things like that and the dreamweaver validator doesn't seem to recognize php so its all on me. I have made the changes you suggested and it still just shows a blank page, it seems as if the browser is not reaching the html? perhaps the structure of my php is preventing it? Link to comment https://forums.phpfreaks.com/topic/148905-calender-with-event-adder/#findComment-782827 Share on other sites More sharing options...
MiCR0 Posted March 12, 2009 Share Posted March 12, 2009 you have removed all of the   from your running script correct? Link to comment https://forums.phpfreaks.com/topic/148905-calender-with-event-adder/#findComment-782850 Share on other sites More sharing options...
matt.sisto Posted March 12, 2009 Author Share Posted March 12, 2009 They do not appear in the running script. ??? Link to comment https://forums.phpfreaks.com/topic/148905-calender-with-event-adder/#findComment-782864 Share on other sites More sharing options...
matt.sisto Posted March 12, 2009 Author Share Posted March 12, 2009 <?php define("ADAY", (60*60*24)); if ((!isset($_POST["month"])) || (!isset($_POST["year"]))) { $nowArray = getdate(); $month = $nowArray["mon"]; $year = $nowArray["year"]; } else { $month = $_POST["month"]; $year = $_POST["year"]; } $start = mktime (12, 0, 0, $month, 1, $year); $firstDayArray = getdate($start); ?> <html> <head> <title><?php echo "Calendar: ".$firstDayArray["month"]." ".$firstDayArray["year"]; ?></title> <head> <body> <h1>Select a Month/Year Combination</h1> <form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>"> <select name="month"> <?php $months = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); for ($x=1; $x <= count($months); $x++) { echo"<option value=\"$x\""; if ($x == $month) { echo " selected"; } echo ">".$months[$x-1]."</option>"; } ?> </select> <select name="year"> <?php for ($x=1980; $x<=2010; $x++) { echo "<option"; if ($x == $year) { echo " selected"; } echo ">$x</option>"; } ?> </select> <input type="submit" name="submit" value="Go!"> </form> <br/> <?php $days = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); echo "<table border=\"1\" cellpadding=\"5\"><tr>\n"; foreach ($days as $day) { echo "<td style=\"background-color: #CCCCCC; text-align: center; width: 14%\"> <strong>$day</strong></td>\n"; } for ($count=0; $count < (6*7); $count++) { $dayArray = getdate($start); if (($count % 7) == 0) { if ($dayArray["mon"] != $month) { break; } else { echo "</tr><tr>\n"; } } if ($count < $firstDayArray["wday"] || $dayArray["mon"] != $month) { echo "<td> </td>\n"; } else { echo "<td>".$dayArray["mday"]." </td>\n"; $start += ADAY; } } echo "</tr></table>"; ?> </body> </html> This is the calendar on its own which works fine, its just adding events. http://salmonsreach.org/calender/showcalender.php Link to comment https://forums.phpfreaks.com/topic/148905-calender-with-event-adder/#findComment-783303 Share on other sites More sharing options...
redarrow Posted March 12, 2009 Share Posted March 12, 2009 Have a look at this a head start for you. <?php define("ADAY", (60*60*24)); if ((!isset($_POST["month"])) || (!isset($_POST["year"]))) { $nowArray = getdate(); $month = $nowArray["mon"]; $year = $nowArray["year"]; } else { $month = $_POST["month"]; $year = $_POST["year"]; } $start = mktime (12, 0, 0, $month, 1, $year); $firstDayArray = getdate($start); ?> <html> <head> <title><?php echo "Calendar: ".$firstDayArray["month"]." ".$firstDayArray["year"]; ?></title> <head> <body> <h1>Select a Month/Year Combination</h1> <form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>"> <select name="month"> <?php $months = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); for ($x=1; $x <= count($months); $x++) { echo"<option value=\"$x\""; if ($x == $month) { echo " selected"; } echo ">".$months[$x-1]."</option>"; } ?> </select> <select name="year"> <?php for ($x=1980; $x<=2010; $x++) { echo "<option"; if ($x == $year) { echo " selected"; } echo ">$x</option>"; } ?> </select> <input type="submit" name="submit" value="Go!"> </form> <br/> <?php $days = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); echo "<table border=\"1\" cellpadding=\"5\"><tr>\n"; foreach ($days as $day) { echo "<td style=\"background-color: #CCCCCC; text-align: center; width: 14%\"> <strong>$day</strong></td>\n"; } for ($count=0; $count < (6*7); $count++) { $dayArray = getdate($start); if (($count % 7) == 0) { if ($dayArray["mon"] != $month) { break; } else { echo "</tr><tr>\n"; } } if ($count < $firstDayArray["wday"] || $dayArray["mon"] != $month) { echo "<td> </td>\n"; } else { echo "<td><a href='".$_SERVER['PHP_SELF']."?add=event&day={$dayArray['mday']}&month={$dayArray['mon']}&year={$dayArray['year']}'>{$dayArray['mday']}</a> </td>\n"; $start += ADAY; } } echo "</tr></table>"; ?> </body> </html> <?php if($_GET['add']=="event"){ echo "Day:\n{$_GET['day']}\n<br>Month\n{$_GET['month']}<br>Year:\n{$_GET['year']}"; } ?> Link to comment https://forums.phpfreaks.com/topic/148905-calender-with-event-adder/#findComment-783333 Share on other sites More sharing options...
matt.sisto Posted March 13, 2009 Author Share Posted March 13, 2009 So I have decided to break it up a bit, I have added a link to the calendar for adding an event, which goes to the addeventform.php, which then goes to addevent.php, which actually puts the data into the table however I am now having issues with putting the date into the table it just defaults the value to 0000-00-00, any ideas? p.s thanks for the last post, and any posts so far. here is the code. addeventform.php (http://salmonsreach.org/addeventform.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> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Add Event</title> </head> <body> <legend> Event Details <form method="post" action="addevent.php"> <input type="text" name="event_title" size="25" maxlength="25" value="<?=$row['event_title']?>"/></p> <p><strong>Event Description:</strong><br/> <input type="text" name="event_shortdesc" size="25" maxlength="255" value="<?=$row['event_shortdesc']?>"/></p> <p><strong>Event Date:</strong><br/> <select name="year" value="<?=$row['y']?>"> <?php for ($x= 2009; $x<=2012; $x++) { echo "<option"; if ($x == $year) { echo " selected"; } echo ">$x</option>"; } ?> </select> <select name="month" value="<?=$row['m']?>"/> <?php $months = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); for ($x=1; $x <= count($months); $x++) { echo"<option value=\"$x\""; if ($x == $month) { echo " selected"; } echo ">".$months[$x-1]."</option>"; } ?> </select> <select name="Day" value="<?=$row['d']?>"> <?php for ($x= 1; $x<=31; $x++) { echo "<option"; if ($x == $day) { echo " selected"; } echo ">$x</option>"; } ?> </select> <p><input type ="submit" value="confirm"/></p> </legend> </form> </body> </html> :addevent.php (this will take you back to the calendar which I have not managed to get to display the added events yet but first things first) <?php require "dbconn2.php"; $event_title = $_POST['event_title']; $event_shortdesc = $_POST['event_shortdesc']; $m = $_POST["m"]; $d = $_POST["d"]; $y = $_POST["y"]; $event_start = $y."-".$m."-".$d." ".$_POST["event_start"]; $sql = "INSERT INTO calender_events VALUES (0,'".$event_title."','".$event_shortdesc."','".$event_start."')"; $result = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); header("Location: calendar3.php"); exit(); ?> <!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> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Add Event</title> </head> <body> </body> </html> Link to comment https://forums.phpfreaks.com/topic/148905-calender-with-event-adder/#findComment-783695 Share on other sites More sharing options...
MiCR0 Posted March 13, 2009 Share Posted March 13, 2009 Bug in your post backs $m = $_POST["month"]; $d = $_POST["Day"]; $y = $_POST["year"]; Try to remember to use print_r($_POST); and then copy the output and then use that output to make your processes code Link to comment https://forums.phpfreaks.com/topic/148905-calender-with-event-adder/#findComment-783783 Share on other sites More sharing options...
matt.sisto Posted March 13, 2009 Author Share Posted March 13, 2009 Thats wicked, thanks Micro. So now I just need to get my calendar to display the added events. Link to comment https://forums.phpfreaks.com/topic/148905-calender-with-event-adder/#findComment-783810 Share on other sites More sharing options...
matt.sisto Posted March 14, 2009 Author Share Posted March 14, 2009 I have noticed a bug in the code for calendar 2 when running it but I'm not sure how to fix it. When you search a date and click on the day link it returns back to march 2009, presumably this is something to do with the nowArray? http://salmonsreach.org/calendar2.php calendar2.php: <?php define("ADAY", (60*60*24)); if ((!isset($_POST["month"])) || (!isset($_POST["year"]))) { $nowArray = getdate(); $month = $nowArray["mon"]; $year = $nowArray["year"]; } else { $month = $_POST["month"]; $year = $_POST["year"]; } $start = mktime (12, 0, 0, $month, 1, $year); $firstDayArray = getdate($start); ?> <html> <head> <title><?php echo "Calendar: ".$firstDayArray["month"]." ".$firstDayArray["year"]; ?></title> <head> <body> <h1>Select a Month/Year Combination</h1> <form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>"> <select name="month"> <?php $months = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); for ($x=1; $x <= count($months); $x++) { echo"<option value=\"$x\""; if ($x == $month) { echo " selected"; } echo ">".$months[$x-1]."</option>"; } ?> </select> <select name="year"> <?php for ($x=1980; $x<=2010; $x++) { echo "<option"; if ($x == $year) { echo " selected"; } echo ">$x</option>"; } ?> </select> <input type="submit" name="submit" value="Go!"> </form> <br/> <?php $days = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); echo "<table border=\"1\" cellpadding=\"5\"><tr>\n"; foreach ($days as $day) { echo "<td style=\"background-color: #CCCCCC; text-align: center; width: 14%\"> <strong>$day</strong></td>\n"; } for ($count=0; $count < (6*7); $count++) { $dayArray = getdate($start); if (($count % 7) == 0) { if ($dayArray["mon"] != $month) { break; } else { echo "</tr><tr>\n"; } } if ($count < $firstDayArray["wday"] || $dayArray["mon"] != $month) { echo "<td> </td>\n"; } else { echo "<td><a href='".$_SERVER['PHP_SELF']."?add=event&day={$dayArray['mday']}&month={$dayArray['mon']}&year={$dayArray['year']}'>{$dayArray['mday']}</a> </td>\n"; $start += ADAY; } } echo "</tr></table>"; ?> </body> </html> <?php if($_GET['add']=="event"){ echo "Day:\n{$_GET['day']}\n<br>Month\n{$_GET['month']}<br>Year:\n{$_GET['year']}"; } ?> Link to comment https://forums.phpfreaks.com/topic/148905-calender-with-event-adder/#findComment-784561 Share on other sites More sharing options...
matt.sisto Posted March 16, 2009 Author Share Posted March 16, 2009 I am going to uni today to sit down and go through it with my lecturer, hopefully I will get the code working today, I will let all of you know when and if I get it working how I did (for those of you that don't already know how to do it). Thanks for all your help so far. Link to comment https://forums.phpfreaks.com/topic/148905-calender-with-event-adder/#findComment-785682 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.