Faisca78 Posted March 19, 2009 Share Posted March 19, 2009 Hi everyone, Back in December I posted a topic where I had problems with my calendar. Even though there were some very helpful users, they couldn't do much because it was in Spanish and, therefore, difficult to follow. I have changed it to English in the hope that someone can help me figure out why it's not working. Now I just get an error message when I load it on the website, although back in December all kinds of things were happening, like freezing the browser. Here's the code: <?php include("functions.php"); $current_time = time(); $day_only_today = date("d",$current_time); if (!$_POST && !isset($_GET["new_months"]) && !isset($_GET["new_year"])){ $months = $_GET['months']; $year = $_GET['year']; }elseif ($_POST) { $months = $_POST["new_months"]; $year = $_POST["new_year"]; }else{ $months = $_GET["new_months"]; $year = $_GET["new_year"]; } if($months == "" || $year == ""){ $year = date("Y"); $months = date("n"); } $last = date("t",mktime(0, 0, 0, $months, 1, $year)); if($months == '12' || $months == '1'){ if($months == '12'){ $next = 1; $prev = $months -1; $nyear = $year + 1; $pyear = $year; } if($months == '1'){ $next = $months + 1; $prev = 12; $nyear = $year; $pyear = $year -1; } }else{ $next = $months + 1; $prev = $months - 1; $pyear = $year; $nyear = $year; } echo "<table width=200 height=10 cellspacing=6 cellpadding=1 border=0> <tr><td colspan=8 align=center class=tit> <table width=100% cellspacing=4 cellpadding=0.5 border=0><tr> <td style=font-size:10pt;font-weight:bold;color:white><a href='".$_SERVER['PHP_SELF']."?months=$prev&year=$pyear' class=prev></a></td> <td class='title'>$month[$months] $year<td> <td align=right style=font-size:10pt;font-weight:bold;color:white><a href='".$_SERVER['PHP_SELF']. "?months=$next&year=$nyear' class=next></a></td> </table>"; echo '<tr> <td width=14% align=center class=altn>M</td> <td width=14% align=center class=altn>T</td> <td width=14% align=center class=altn>O</td> <td width=14% align=center class=altn>T</td> <td width=14% align=center class=altn>F</td> <td width=14% align=center class=altn>L</td> <td width=14% align=center class=altn>S</td> <td width=18% align=center class=altn>Vecka</td> </tr>'; $cday = "1"; $dayz = loadmatrix($last,$months,$year); $j = 0; while($cday <= $last){ $day = date("D",mktime(0,0,0,$months,$cday,$year)); # returns the day of the week in letters... $date = date("j",mktime(0,0,0,$months,$cday,$year)); #returns the day of the month in 01/31 $day_week = date("w",mktime(0,0,0,$months,$cday,$year)); #retorna el day de la week en numero $event = $year."-".$month_num[$months]."-".$date; if($day == "Mon"){ echo "</tr><tr>"; } if($date == "1"){ $i=1; while($i != $day_week){ echo "<td> </td>"; $i++; } } if($year == date("o") && $month[$months] == $month[date("n")] && $date == date("j")){ if($date == $dayz[$j] ){ echo "<td class='tdday' align='center'><b><a href='index.php?event=$event' target='_self'>$date</a></b></td>"; $j++; }else{ echo "<td class='calendar' align='center'><b>$date</b></td>"; } }else{ if($date == $dayz[$j] ){ echo "<td class='tdday' align='center'><b><a href='index.php?event=$event' target='_self'>$date</a></b></td>"; $j++; }else{ //Sundays if ($day_week == 0){ echo "<td align='center' class='tddom'>$date</td>"; echo "<td align='center' class='week'>".strftime("%V", strtotime("$adate")). "</td>"; }else{ echo "<td align='center'>$date</td>";} } } $cday++; } echo "</tr>"; ?> </table> <div id="date_drop"> <table> <?php function calendarForm($months,$year){ echo ' <table width=200 align="center" cellspacing="1" cellpadding="1" border="0" class=tform> <tr><form action="index.php? '.$_SERVER['PHP_SELF'].' " method="POST">'; echo ' <td align="center" valign="top"> <select name=new_months class="select_month"> <option value="1"'; if ($months==1) echo "selected"; echo'>Januari <option value="2" '; if ($months==2) echo "selected"; echo'>Februari <option value="3" '; if ($months==3) echo "selected"; echo'>Mars <option value="4" '; if ($months==4) echo "selected"; echo '>April <option value="5" '; if ($months==5) echo "selected"; echo '>Maj <option value="6" '; if ($months==6) echo "selected"; echo '>Juni <option value="7" '; if ($months==7) echo "selected"; echo '>Juli <option value="8" '; if ($months== echo "selected"; echo '>Augusti <option value="9" '; if ($months==9) echo "selected"; echo '>September <option value="10" '; if ($months==10) echo "selected"; echo '>Oktober <option value="11" '; if ($months==11) echo "selected"; echo '>November <option value="12" '; if ($months==12) echo "selected"; echo '>December </select> </td>'; echo ' <td align="center" valign="top"> <select name=new_year class="select_yr">'; for ($cont=2006;$cont<$year+3;$cont++){ echo "<option value='$cont'"; if ($year==$cont) echo " selected"; echo ">$cont"; } echo ' </select> </td>'; echo ' <td colspan="1" align="center" valign="top"><input type="Submit" value="GÅ" class="button" /></td> </table> </form>'; } calendarForm($months,$year); ?> </table> <div id="events"> <table> <?php $event = $_GET['event']; if(!isset($event)){ $event = date("Y-m-d"); } $connection = connect(); $sql = "select * from events where date = '$event'"; $res = query($sql); if(mysql_num_rows($res) > 0){ while($line = mysql_fetch_array($res)){ echo "<tr><td class='tddate'>".$line['date']."</td></tr> <tr><td class='tdevent'>".$line['event']."</td></tr>"; } }else{ echo "<tr><td></td></tr>"; } disconnect($connection); ?> This is the error message I get: Parse error: syntax error, unexpected T_LOGICAL_OR in /www/110mb.com/i/l/l/u/m/i/n/o/illumino/htdocs/functions.php on line 33 And this is the code for my functions document: <?php $data; $month[1] = "Januari"; $month[2] = "Februari"; $month[3] = "Mars"; $month[4] = "April"; $month[5] = "Maj"; $month[6] = "Juni"; $month[7] = "Juli"; $month[8] = "Augusti"; $month[9] = "September"; $month[10] = "Oktober"; $month[11] = "November"; $month[12] = "December"; $month_num[1] = "01"; $month_num[2] = "02"; $month_num[3] = "03"; $month_num[4] = "04"; $month_num[5] = "05"; $month_num[6] = "06"; $month_num[7] = "07"; $month_num[8] = "08"; $month_num[9] = "09"; $month_num[10] = "10"; $month_num[11] = "11"; $month_num[12] = "12"; $days[0] = "0"; function connect(){ //Put down the data for your localhost connection $host = "localhost"; $userdb = "my_db"; // I put my user db here $pwddb = "pswd"; //I put my password here $db = "db"; //I put the db name here $link = mysql_connect($host,$userdb,$pwddb); or die("It couldn't connect : " . mysql_error()); if (!$link) { die('Not connected : ' . mysql_error()); } $seldb = mysql_select_db($db,$link); if (!$seldb) { die ('Can't use events': ' . mysql_error()); } return $link; } function disconnect($connection){ mysql_close($connection); } function query($sql){ $res = mysql_query($sql) or die (mysql_error()); return $res; } function findevents($last,$months,$year){ $connection = connect(); $from = $year."-".$months."-01"; $to = $year."-".$months."-".$last; $sql = "select * from events where date BETWEEN '$from' and '$to'"; $res = query($sql); if(mysql_num_rows($res) > 1){ echo "<tr><th>DATE</th><th>EVENT</th></tr>"; while($line = mysql_fetch_array($res)){ echo "<tr><td class='tddate'>".$linea['date']."</td><td class='tdevent'>".$line['event']."</td></tr>"; } }else{ echo "<tr><td class='tdno'>There are no events for this month</td></tr>"; } disconnect($connection); } function loadmatrix($last,$months,$year){ $i = 0; $connection = connect(); $from = $year."-".$months."-01"; $to = $year."-".$months."-".$last; // $sql = "select * from events where date BETWEEN '$from' and '$to' order by date"; $sql = "select distinct date from events where date BETWEEN '$from' and '$to' order by date"; $res = query($sql); if(mysql_num_rows($res) > 0){ while($line = mysql_fetch_array($res)){ $date = $line['date']; $day = explode("-", $date); //if($days[$i-1] != $day[2]){ $days[$i] = $days[2]; //} $i++; } }else{ $days[0] = "0"; } disconnect($connection); return $days; } function redirect($time,$url){ print "<meta http-equiv=Refresh content=\"$time ; url=$url\">"; } ?> I would appreciate any help to resolve this issue, as it's been forever and I just want it to work properly. I'm not so good with PHP, so I do need as much help as possible. Thank you so much, Nat Quote Link to comment Share on other sites More sharing options...
Kalland Posted March 19, 2009 Share Posted March 19, 2009 Remove the ";" before "or" in this line: $link = mysql_connect($host,$userdb,$pwddb); or die("It couldn't connect : " . mysql_error()); Quote Link to comment Share on other sites More sharing options...
Faisca78 Posted March 19, 2009 Author Share Posted March 19, 2009 Hi Kalland, Thank you for your help. That did help and the functions.php is now functional. However, I think there's an error in my main php code for the calendar, because when I open the page where it's at, the browser freezes. This is where it can be found: http://illumino.110mb.com This is the code for the calendar: <?php include("functions.php"); $current_time = time(); $day_only_today = date("d",$current_time); if (!$_POST && !isset($_GET["new_months"]) && !isset($_GET["new_year"])){ $months = $_GET['months']; $year = $_GET['year']; }elseif ($_POST) { $months = $_POST["new_months"]; $year = $_POST["new_year"]; }else{ $months = $_GET["new_months"]; $year = $_GET["new_year"]; } if($months == "" || $year == ""){ $year = date("Y"); $months = date("n"); } $last = date("t",mktime(0, 0, 0, $months, 1, $year)); if($months == '12' || $months == '1'){ if($months == '12'){ $next = 1; $prev = $months -1; $nyear = $year + 1; $pyear = $year; } if($months == '1'){ $next = $months + 1; $prev = 12; $nyear = $year; $pyear = $year -1; } }else{ $next = $months + 1; $prev = $months - 1; $pyear = $year; $nyear = $year; } echo "<table width=200 height=10 cellspacing=6 cellpadding=1 border=0> <tr><td colspan=8 align=center class=tit> <table width=100% cellspacing=4 cellpadding=0.5 border=0><tr> <td style=font-size:10pt;font-weight:bold;color:white><a href='".$_SERVER['PHP_SELF']."?months=$prev&year=$pyear' class=prev></a></td> <td class='title'>$month[$months] $year<td> <td align=right style=font-size:10pt;font-weight:bold;color:white><a href='".$_SERVER['PHP_SELF']. "?months=$next&year=$nyear' class=next></a></td> </table>"; echo '<tr> <td width=14% align=center class=altn>M</td> <td width=14% align=center class=altn>T</td> <td width=14% align=center class=altn>O</td> <td width=14% align=center class=altn>T</td> <td width=14% align=center class=altn>F</td> <td width=14% align=center class=altn>L</td> <td width=14% align=center class=altn>S</td> <td width=18% align=center class=altn>Vecka</td> </tr>'; $cday = "1"; $dayz = loadmatrix($last,$months,$year); $j = 0; while($cday <= $last){ $day = date("D",mktime(0,0,0,$months,$cday,$year)); # returns the day of the week in letters... $date = date("j",mktime(0,0,0,$months,$cday,$year)); #returns the day of the month in 01/31 $day_week = date("w",mktime(0,0,0,$months,$cday,$year)); #retorna el day de la week en numero $event = $year."-".$month_num[$months]."-".$date; if($day == "Mon"){ echo "</tr><tr>"; } if($date == "1"){ $i=1; while($i != $day_week){ echo "<td> </td>"; $i++; } } if($year == date("o") && $month[$months] == $month[date("n")] && $date == date("j")){ if($date == $dayz[$j] ){ echo "<td class='tdday' align='center'><b><a href='index.php?event=$event' target='_self'>$date</a></b></td>"; $j++; }else{ echo "<td class='calendar' align='center'><b>$date</b></td>"; } }else{ if($date == $dayz[$j] ){ echo "<td class='tdday' align='center'><b><a href='index.php?event=$event' target='_self'>$date</a></b></td>"; $j++; }else{ //Sundays if ($day_week == 0){ echo "<td align='center' class='tddom'>$date</td>"; echo "<td align='center' class='week'>".strftime("%V", strtotime("$adate")). "</td>"; }else{ echo "<td align='center'>$date</td>";} } } $cday++; } echo "</tr>"; ?> </table> <div id="date_drop"> <table> <?php function calendarForm($months,$year){ echo ' <table width=200 align="center" cellspacing="1" cellpadding="1" border="0" class=tform> <tr><form action="index.php? '.$_SERVER['PHP_SELF'].' " method="POST">'; echo ' <td align="center" valign="top"> <select name=new_months class="select_month"> <option value="1"'; if ($months==1) echo "selected"; echo'>Januari <option value="2" '; if ($months==2) echo "selected"; echo'>Februari <option value="3" '; if ($months==3) echo "selected"; echo'>Mars <option value="4" '; if ($months==4) echo "selected"; echo '>April <option value="5" '; if ($months==5) echo "selected"; echo '>Maj <option value="6" '; if ($months==6) echo "selected"; echo '>Juni <option value="7" '; if ($months==7) echo "selected"; echo '>Juli <option value="8" '; if ($months== echo "selected"; echo '>Augusti <option value="9" '; if ($months==9) echo "selected"; echo '>September <option value="10" '; if ($months==10) echo "selected"; echo '>Oktober <option value="11" '; if ($months==11) echo "selected"; echo '>November <option value="12" '; if ($months==12) echo "selected"; echo '>December </select> </td>'; echo ' <td align="center" valign="top"> <select name=new_year class="select_yr">'; for ($cont=2006;$cont<$year+3;$cont++){ echo "<option value='$cont'"; if ($year==$cont) echo " selected"; echo ">$cont"; } echo ' </select> </td>'; echo ' <td colspan="1" align="center" valign="top"><input type="Submit" value="GÅ" class="button" /></td> </table> </form>'; } calendarForm($months,$year); ?> </table> <div id="events"> <table> <?php $event = $_GET['event']; if(!isset($event)){ $event = date("Y-m-d"); } $connection = connect(); $sql = "select * from events where date = '$event'"; $res = query($sql); if(mysql_num_rows($res) > 0){ while($line = mysql_fetch_array($res)){ echo "<tr><td class='tddate'>".$line['date']."</td></tr> <tr><td class='tdevent'>".$line['event']."</td></tr>"; } }else{ echo "<tr><td></td></tr>"; } disconnect($connection); ?> Somebody told me at some point that there seemed to be a loop and that's why it froze, but I could not find one. Any ideas on why it gets stuck?? Thanks so much, Nat 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.