Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: mktime error

  1. #1
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    mktime error

    I am new to php coding and have created a calendar. When I add a new event, I get the following error, though teh new event is added to the calendar.

    Warning: mktime() expects parameter 6 to be long, string given in C:\wamp\www\Project 3\SimpleCalendar\view.php on line 21

    Here is my code - with line 21 marked:

    Code:
    <?php
    session_start();
    require("config.php");
    
    if(isset($_SESSION['LOGGEDIN']) == FALSE) {
    header("Location: " . $config_basedir);
    }
    
    function short_event($name) {
    $final = "";
    $final = (substr($name, 0, 12) . "...");
    return $final;
    }
    
    require("header.php");
    if(isset($_GET['error'])) {
    echo "<script>newEvent('" . $_GET['eventdate'] . "', 1)</script>";
    }
    
    $cols = 7;
    $weekday = date("w", mktime(0, 0, 0, $month, 1, $year)); // line 21
    $numrows = ceil(($numdays + $weekday) / $cols);
    echo "<br />";
    echo "<table class='cal' cellspacing=0 cellpadding=5 border=1>";
    echo "<tr>";
    echo "<th class='cal'>Sunday</th>";
    echo "<th class='cal'>Monday</th>";
    echo "<th class='cal'>Tuesday</th>";
    echo "<th class='cal'>Wednesday</th>";
    echo "<th class='cal'>Thursday</th>";
    echo "<th class='cal'>Friday</th>";
    echo "<th class='cal'>Saturday</th>";
    echo "</tr>";
    $counter = 1;
    $newcounter = 1;
    
    echo "<tr>";
    $daysleft = 6 - $weekday--;
    for($f=0;$f<=$weekday;$f++) {
    echo "<td class='cal_date' width='110' height='10'>";
    echo "</td>";
    }
    
    for($f=0;$f<=$daysleft;$f++) {
    echo "<td class='cal_date' width='100' height='10'>";
    $display = date("jS", mktime(0, 0, 0, $month, $counter, $year));
    $todayday = date("d");
    $todaymonth = date("n");
    $todayyear = date("Y");
    if($counter == $todayday AND $month == $todaymonth AND
    $year == $todayyear) {
    echo "<strong>TODAY " . $display . "</strong>";
    }
    else {
    echo $display;
    }
    echo "</td>";
    $counter++;
    }
    echo "</tr>";
    
    echo "<tr>";
    for($f=0;$f<=$weekday;$f++) {
    echo "<td class='cal' width='110' height='10'>";
    if($newcounter <= $numdays) {
    }
    echo "</td>";
    }
    
    for($f=0;$f<=$daysleft;$f++) {
    echo "<td class='cal' width='110' height='40'>";
    $date = $year . "-" . $month . "-" . $newcounter;
    echo "<a class='cal' href='#' onclick=\"newEvent('" . $date . "')\"></a>";
    $eventsql = "SELECT * FROM events WHERE date = '" . $date . "';";
    $eventres = mysql_query($eventsql);
    while($eventrow = mysql_fetch_assoc($eventres)) {
    echo "<a class='deleteevent' href='delete.php?id=" . $eventrow['id'] . "' onclick=\"return confirm('Are you sure you want to delete `" . $eventrow['name'] ."`?');\">X</a>";
    echo "<a class='event' href='#' onclick='getEvent(" . $eventrow['id'] . ")'>" . short_event($eventrow['name']) . "</a><br />";
    }
    echo "</td>";
    $newcounter++;
    }
    echo "</tr>";
    
    for($i=1;$i<=($numrows-1);$i++) {
    echo "<tr>";
    for($a=0;$a<=($cols-1);$a++) {
    echo "<td class='cal_date' width='110' height='10'>";
    $display = date("jS", mktime(0, 0, 0, $month, $counter,
    $year));
    $todayday = date("d");
    $todaymonth = date("n");
    $todayyear = date("Y");
    if($counter == $todayday AND $month == $todaymonth AND
    $year == $todayyear) {
    echo "<strong>TODAY " . $display . "</strong>";
    }
    else {
    echo $display;
    }
    echo "</td>";
    
    $counter++;
    }
    echo "</tr>";
    echo "<tr>";
    for($aa=1;$aa<=$cols;$aa++) {
    echo "<td class='cal' width='110' height='40'>";
    if($newcounter <= $numdays) {
    $date = $year . "-" . $month . "-" . $newcounter;
    echo "<a class='cal' href='#' onclick=\"newEvent('" . $date . "')\"></a>";
    $eventsql = "SELECT * FROM events WHERE date = '" . $date . "';";
    $eventres = mysql_query($eventsql);
    while($eventrow = mysql_fetch_assoc($eventres)) {
    echo "<a class='deleteevent' href='delete.php?id=" . $eventrow['id'] . "' onclick=\"return confirm('Are you sure
    you want to delete `" . $eventrow['name'] ."`?');\">X</a>";
    echo "<a class='event' href='#' onclick='getEvent(" . $eventrow['id'] . ")'>" . short_event($eventrow['name']) . "</a><br />";
    }
    }
    echo "</td>";
    $newcounter++;
    }
    echo "</tr>";
    }
    
    echo "</table>";
    require("footer.php");
    ?>
    Can anyone tell me is causing the error and how to fix it?

    Thanks - SueBee710

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    Try a 4 digit year

  • #3
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks. The problem was IE (I use version 9). My code runs in Foxfire, Chrome, Safari, and Opera without a hitch!
    Last edited by SueBee710; 07-13-2012 at 07:53 PM. Reason: Thread needs to be closed.

  • #4
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can someone please tell me how to mark my thread as Resolved? I cannot figure out how to do that.
    Thank you.
    Last edited by SueBee710; 07-12-2012 at 07:33 PM.

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You can modify the first post and change the title.
    That won't resolve your problem though. Browser's won't interfere with server processing code, so your issue lies elsewhere.

    Where have you defined $month and $year for this block:
    PHP Code:
    $weekday date("w"mktime(000$month1$year)); // line 21 
    ?

  • #6
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thread resolved

  • #7
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Close thread: Resolved

    Thank you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •