Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parse error, unexpected $

Status
Not open for further replies.

jwigal

Programmer
Mar 16, 2001
31
US
I have been throgh this code upside down, backwards, forwards, commented out sections, and just cannot seem to see where my misplaced bracket might be. It was working really well a day or so ago, and somehow I broke it...

The specific error I am getting is:

Parse error: parse error, unexpected $ in /my/path/is/here/dotinfo/ref_availability.php on line 458

Line 458 is the last line after the trailing ?>

I commented out a number of sections to see if I can narrow down the issue, and I've determined that the offending code may be somewhere in the [red]colored[/red] section. When I comment out the red section, it runs without seeing the parse error.

Each of the functions at the top of the page seem to check out (e.g. I comment out each function between the curly braces, and i get the same error)

Code:
<?php
	require_once('includes/header.php');
	require_once('includes/htmlheader.php');
	require_once('HTML/QuickForm.php');
	require_once "Auth.php";
	require_once 'Calendar/Month/Weekdays.php';
	require_once "MDB.php";
	require_once 'Date.php';

	function series_avail ($values) {
		$db = MDB::connect(PGSQL_REFASST);
		if (MDB::isError($db)) {
			echo "DSN " . $pgsql_refasst;
			die ($db->getMessage());
		}
		print_r($values);


		$date = array('Y' => $values['startdate']['Y'],
			'M' => $values['startdate']['M'],
			'd' => $values['startdate']['d']);
		$enddate = array('Y' => $values['enddate']['Y'],
			'M' => $values['enddate']['M'],
			'd' => $values['enddate']['d']);
		print_r($date);	
		$d = new Date_Calc();
		$iterations = 0;
		$sql = "insert into dotinfo_availability (availability_customer_id, availability_referee_id, ".
			"availability_date, availability_start_time, availability_end_time) ".
			"values ( ".getCustomerID($values['user']).", "
			.getRefereeID($values['user']).", '" 
			. $date['Y']."-". $date['M']."-". $date['d']."', '"
			.$values['starttime']['h'] .":".$values['starttime']['i']."', '"
			.$values['endtime']['h'] .":".$values['endtime']['i']."')";

		echo "<br><br>".$sql."\r";


		while (mktime(0,0,0,$date['M'],$date['d'],$date['Y']) <= 
		mktime(0,0,0,$enddate['M'],$enddate['d'],$enddate['Y']) 
		and $iterations <100) {

			$iterations = $iterations +1; 		
			$sql = "insert into dotinfo_availability (availability_customer_id, availability_referee_id, ".
				"availability_date, availability_start_time, availability_end_time) ".
				"values ( ".getCustomerID($values['user']).", "
				.getRefereeID($values['user']).", '" 
				. $date['Y']."-". $date['M']."-". $date['d']."', '"
				.$values['starttime']['h'] .":".$values['starttime']['i']."', '"
				.$values['endtime']['h'] .":".$values['endtime']['i']."')";


			switch ($values['frequency']) {
				case '7':
					echo "<br><br>".$sql;
					echo "<br>EXECUTE.<br>";
					$res = $db->query($sql);
					if (MDB::isError($db)) {
						echo "INSERT error:" . $db->getMessage();
					}else{
						echo "<p>Record inserted successfully.</p>";
					}

				break;

				case '1':
					// if current date meets criteria, execute sql
					echo "<br><br>".$sql;

					if ($d->dayOfWeek($date['d'],$date['M'],$date['Y']) == $values['weekday']) {
						$res = $db->query($sql);
						if (MDB::isError($db)) {
							echo "INSERT error:" . $db->getMessage();
						}else{
							echo "<p>Record inserted successfully.</p>";
						}

					}else{
						echo "<br>SKIP.<br>";
					}

				break;

				case '5':
					// if current date meets criteria, execute sql
					echo "<br><br>".$sql;

					if ($d->dayOfWeek($date['d'],$date['M'],$date['Y']) == 0 
						OR $d->dayOfWeek($date['d'],$date['M'],$date['Y']) == 6) {
						
						echo "<br>SKIP.<br>";

					}else{
						$res = $db->query($sql);
						if (MDB::isError($db)) {
							echo "INSERT error:" . $db->getMessage();
						}else{
							echo "<p>Record inserted successfully.</p>";
						}
					}
				break;


			} //end switch
			//move next
			$date = array('Y'=> $d->nextDay($date['d'],$date['M'],$date['Y'],"%Y"),
					'M'=> $d->nextDay($date['d'],$date['M'],$date['Y'],"%m"), 
					'd' =>$d->nextDay($date['d'],$date['M'],$date['Y'],"%e")
				);


		}// end while

	}

	function insert_avail ($values) {

		$db = MDB::connect(PGSQL_REFASST);
		if (MDB::isError($db)) {
			echo "DSN " . $pgsql_refasst;
			die ($db->getMessage());
		}

		$starttime = "";
		$endtime = "";
		if ($values['starttime']['A'] == 'AM'){
			$starttime .= $values['starttime']['h'];
		}else{
			$starttime .= $values['starttime']['h']+12;
		}
		if ($values['endtime']['A'] == 'AM'){
			$endtime .= $values['endtime']['h'];
		}else{
			$endtime .= $values['endtime']['h']+12;
		}

		$starttime .= ":" . $values['starttime']['i'];
		$endtime .= ":" . $values['endtime']['i'];

		$availdate = $values['mydate']['Y'] . "-" .$values['mydate']['M']. "-" .$values['mydate']['d'];

		$sql = "INSERT INTO dotinfo_availability (availability_referee_id, availability_customer_id, "
			."availability_date, availability_start_time, availability_end_time) "
			. "VALUES (" . getRefereeID($values['user']) . ", " 
			.  getCustomerID($values['user'])  
			.  ", '$availdate','$starttime','$endtime')";
		echo "<br><br>".$sql;
		print_r($values['starttime'] );
		print_r($values['endtime'] );
		print_r($values['mydate'] );
		$res = $db->query($sql);

		if (MDB::isError($db)) {
			echo "INSERT error:" . $db->getMessage();
		}else{
			echo "<p>Record inserted successfully.</p>";
		}
	}

	function AddEntryFromCalendar($month, $day, $year, $customerid, $refid) {

		$db = MDB::connect(PGSQL_REFASST);
		if (MDB::isError($db)) {
			echo "DSN " . $pgsql_refasst;
			die ($db->getMessage());
		}



		$sql = "INSERT INTO dotinfo_availability (availability_referee_id, availability_customer_id, "
			."availability_date, availability_start_time, availability_end_time) "
			."VALUES ($refid, $customerid, '$year-$month-$day', '00:01:00','23:59:00')";
		//echo "<br><br>".$sql;
		$res = $db->query($sql);

		if (MDB::isError($db)) {
			echo "INSERT error:" . $db->getMessage();
		}else{
			echo "<p>Record inserted successfully.</p>";
		}


	}	


	function RemoveEntryFromCalendar($month, $day, $year, $customerid, $refid) {

		$db = MDB::connect(PGSQL_REFASST);
		if (MDB::isError($db)) {
			echo "DSN " . $pgsql_refasst;
			die ($db->getMessage());
		}



		$sql = "DELETE FROM dotinfo_availability WHERE availability_date = '$year-$month-$day' "
			."AND availability_customer_id = $customerid "
			."AND availability_referee_id = $refid";
		//echo "<br><br>".$sql;
		$res = $db->query($sql);

		if (MDB::isError($db)) {
			echo "DELETE error:" . $db->getMessage();
		}else{
			echo "<p>Record removed successfully.</p>";
		}


	}	



	$a = new Auth("DB", unserialize(AUTH_PARAM_ARRAY));

	$a->start();
	if ($logout =="1")  {
	//echo "logout called";
		$a->logout();
		$a->start();
	}

	if ($a->checkAuth()) {
		/*
		* The output of your site goes here.
		*/
		if ($action=="add") {
			AddEntryFromCalendar ($month, $day, $year, 
				getcustomerID($a->getUserName()), 
				getrefereeID ($a->getUserName()) );
		}

		if ($action=="remove") {
			RemoveEntryFromCalendar ($month, $day, $year, 
				getcustomerID($a->getUserName()), 
				getrefereeID ($a->getUserName()) );
		}


		echo "<h2>This is the ref availability page.</h2>";

		$customerid = getcustomerID($a->getUserName());
		$RefID = getrefereeID($a->getUserName());

		$db = MDB::connect(PGSQL_REFASST);
		if (MDB::isError($db)) {
			echo "DSN " . $pgsql_refasst;
			die ($db->getMessage());
		}

		$sql = "SELECT DISTINCT availability_date FROM dotinfo_availability "
			."WHERE availability_start_time = '00:01:00' "
			."AND availability_end_time = '23:59:00' "
			."AND availability_referee_id = $RefID "
			."AND availability_customer_id = $customerid";

		//echo "<br><br>".$sql;
		$res = $db->query($sql);

		if (MDB::isError($db)) {
			echo "allday error:" . $db->getMessage();
		}

		$avail_allday = $db->fetchCol($res);
		echo "<!-- ";
		print_r($avail_allday);
		echo "-->";

		$sql = "SELECT DISTINCT availability_date FROM dotinfo_availability "
			."WHERE (availability_start_time <> '00:01:00' "
			."OR availability_end_time <> '23:59:00' ) "
			."AND availability_referee_id = $RefID "
			."AND availability_customer_id = $customerid";

		//echo "<br><br>".$sql;
		$res = $db->query($sql);

		if (MDB::isError($db)) {
			echo "partial day error:" . $db->getMessage();
		}

		$avail_part_day = $db->fetchCol($res);
		echo "<!-- ";
		print_r($avail_part_day);
		echo "-->";

		echo "<center><table><tr valign=\"top\">";
		[red]for ($i = 0; $i <= 5 ; $i++) {  //start six calendar for loop
			echo "<td>";

			if (date('n') + $i > 12 ){ 
				$dayuse = mktime(0,0,0,date('n')-12 + $i,1,date('Y')+1); 
			}else{ 
				$dayuse = mktime(0,0,0,date('n') + $i ,1,date('Y'));
			}

			$Month = new Calendar_Month_Weekdays(date('Y',$dayuse), date('n',$dayuse),0);

			$Month->build();
			echo "<!-- ";
			print_r($Month);
			echo "-->";

			echo "<b>".date("M Y", $dayuse)."</b><br>";
			echo "<table border = \"1\">\n";
			echo "<tr><td>Sun</td><td>Mon</td><td>Tue</td><td>Wed</td><td>Thu</td><td>Fri</td><td>Sat</td>";
			while ($Day = $Month->fetch() ) {
				if ($Day->isFirst() ) {
					echo "<tr>\n";
				}

				if ($Day->isEmpty() ) {
					echo "<td>&nbsp;</td>\n";
				} else {
					echo "<td><a href=\"ref_availability.php?day=". $Day->thisDay();
					echo "&month=".date("n",$dayuse);
					echo "&year=".date("Y",$dayuse);
					echo "&action=add";
					echo "\"><b>";
					echo $Day->thisDay()."</b></a><br>&nbsp;";
					if ($Day->ThisMonth() < 10) {
						$tmpMonth= "0" . $Day->ThisMonth();
					}else{
						$tmpMonth= $Day->ThisMonth();
					}
					if ($Day->ThisDay() < 10) {
						$tmpDay= "0" . $Day->ThisDay();
					}else{
						$tmpDay= $Day->ThisDay();
					}

					if (
						array_search(
							$Day->thisYear() . "-".$tmpMonth."-".$tmpDay,$avail_allday)
							) {
						echo "<a href=\"ref_availability.php?day=". $Day->thisDay();
						echo "&month=".date("n",$dayuse);
						echo "&year=".date("Y",$dayuse);
						echo "&action=remove";
						echo "\">X</a> ";
					}
					if (array_search(
						$Day->thisYear() . "-".$tmpMonth."-".$tmpDay,$avail_part_day)) {
						echo "+";
					}
					echo "</td>\n";
				}//end isempty else
			`		
				if ($Day->isLast()) {
					echo "</tr>\n";
				}
			}; //end single month  calendar 'while loop'

			echo "</table>\n";
			echo "</td>";
			if ($i == 2 ){
				echo "</tr><tr valign=\"top\">";
			}
		}//end six calendars 'for loop'
[/red]
		
		echo "</tr></table></center>";

		$options = array(
			'language'  => 'en',
			'format'    => 'dMY', 
			'minYear'   => date('Y'), 
			'maxYear'   => date('Y') +1 
		);  

		$options_time = array(
			'language'  => 'en',
			'format'    => 'hiA'
		);  

		$date_defaults = array(
			'd' => date('d'),        
			'M' => date('n'),
			'Y' => date('Y')
		);

		$start_defaults = array(
			'h' => 1,        
			'i' => 0,
			'A' => 'AM'
		);

		$end_defaults = array(
			'h' => 11,        
			'i' => 00,
			'A' => 'PM'
		);

		$form = new HTML_QuickForm('frmAddAvailability', 'post');
		$form->addElement('header', 'MyHeader', 'Add Availability');
		$form->setDefaults(
			array('mydate' => $date_defaults,
				'starttime' =>$start_defaults,
				'endtime' => $end_defaults,
				'mydate' => $options,
			'user' => $a->getUserName() )
		);
		$form->addElement('date', 'mydate', 'Choose date', $options);
		$form->addElement('date', 'starttime', 'Start Time',$options_time);
		$form->addElement('date', 'endtime', 'End Time',$options_time);
		$form->addElement('submit', 'btnSubmit', 'Submit');
		$form->addElement('hidden', 'user');

		if ($form->validate()) {
			$form->process('insert_avail',false);
			$form->setDefaults(Null);
			$form->Display();
		}else {
			$form->display();
		}

		$opt_freq = array('7' => 'Daily',
			'5' => 'Monday-Friday',
			'1' => 'Single Weekday'
		);

		$opt_weekday = array ('0' => 'Sunday',
			'1' => 'Monday',
			'2' => 'Tuesday',
			'3' => 'Wednesday',
			'4' => 'Thursday',
			'5' => 'Friday',
			'6' => 'Saturday'
		);

		$form2 = new HTML_QuickForm('frmSeriesAvailability', 'post');
		$form2->addElement('header', 'MyHeader', 'Add Availability');
		$form2->setDefaults(
			array('startdate' => $date_defaults,
				'enddate' => $date_defaults,
				'starttime' => $start_defaults,
				'endtime' => $end_defaults,
				'user' => $a->getUserName()	)
		);
		$form2->addElement('date', 'startdate', 'Start date', $options);
		$form2->addElement('date', 'enddate', 'End date', $options);
		$form2->addElement('select', 'weekday', 'Weekday', $opt_weekday);
		$form2->addElement('select', 'frequency', 'Frequency', $opt_freq);

		$form2->addElement('date', 'starttime', 'Start Time',$options_time);
		$form2->addElement('date', 'endtime', 'End Time',$options_time);

		$form2->addElement('submit', 'btnSubmit', 'Submit');
		$form2->addElement('hidden', 'user');

		if ($form2->validate()) {
			$form2->process('series_avail',false);
			$form2->setDefaults(Null);
			$form2->Display();
		}else {
			$form2->display();
		}



	} //end authenticated content
	
	require_once('includes/footer.php');
	require_once('includes/htmlfooter.php');
?>

----------
Jeff Wigal
Referee Assistant for MS Access
 
The "parse error at $" or "parse error at $end" errors are always caused by not closing punctuation that comes in pairs, such as curly-braces, square-brackets, parentheses, or quotes.

I recommend that you concentrate your efforts looking for that kind of typo.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I'd recommend looking for a missing ).

[root@localhost ~]# grep -c "(" test.php
175
[root@localhost ~]# grep -c ")" test.php
174 <-- ooh looky, one missing.


______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
I've been looking at the code, plus counting my quotes to make sure it's an even number, and that brackets { [ and ( are all identical to their right-sided brethren... any other thoughts on places to look?

----------
Jeff Wigal
Referee Assistant for MS Access
 
I believe you've miscounted.

As KarveR has pointed out, and as I can verify, your script has 175 open-parenthesis characters ("("), but only 174 close-parenthesis characters (")").

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I'm not super familiar with Unix commands, but it looks like the grep -c will give me a count of the number of lines (not necessarily the number of occurrences) of a regular expression. For example, if a parenthesis occurs twice on the same line, it only counts it once. To me, this would not necessarily indicate that they are out of balance.

The reason I say this is that, when I do a search-and-replace on "(" or ")" using Word or any text editor, I get 224 for each. Would this not indicate they are evenly matched, or am I completely missing something?

I'm also getting similar results on [ and {... I also have an even number of single and double quotes.

When I comment out the red section, the errors go away... I'm contemplating re-writing that section by hand and seeing if I can get it to work.

----------
Jeff Wigal
Referee Assistant for MS Access
 
hmmm .... he's actually right, ... back in a few, banging some rocks together.


______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Thanks for your assistance everyone... I ended up pulling out and rebuilding a portion of the code, now it seems to work just fine.

I have no idea what was the problem of the previous code, but hey, it works now...

----------
Jeff Wigal
Referee Assistant for MS Access
 
Glad you found it Jeff, I hit the sack in the end, it was doing my swede in looking at it :/

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
i've experienced before where i KNEW my code was right, but php kept throwing an error, and i finally literally copied and pasted the exact entire contents into another file and it worked fine. as if php was caching an older bad version? i've only seen that once or twice though.

perhaps try uncommenting one statement at a time to find the offending code?


-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
I'm still puzzled at how grep was mis-reporting the counts, I guess there was a spurious non-printable or two in the original.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top