p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: undefined function: view_record()


Message #1 by concepts101@h... on Tue, 12 Feb 2002 01:14:38
I am completely confused why this is happening. Please take a look!

In chap. 12 when I try to view record I get this error:

Call to undefined function: view_record() in /userviewer.php on line 236



line 236 is the view_record section of the switch statement:

switch($action) {  

	case "view_record":

		view_record(); //line #236

	break;

	default:

		list_records();

	break;

Following is my function:

//VIEW RECORD

function view_record() {

	global $default_dbname, $user_tablename, $access_log_tablename;

	global $userid;

	global $PHP_SELF;

	

	if(empty($userid)) error_message('Empty User ID');

	

	$link_id = db_connect($default_dbname);

	

	if(!$link_id) error_message(sql_error());

	

//EDIT AREA

//EDIT QUERY TO REFLECT REAL DATABASE AND TABLE FIELDS

	$query = "SELECT usernumber, userid, username, usercountry, 

useremail, userprofile, registerdate, lastaccesstime FROM $user_tablename 

WHERE userid = '$userid'";

	$result = mysql_query($query);

	

	if(!$result) error_message(sql_error());



//EDIT AREA

//EDIT THE FOLLOWING TO REFLECT PREVIOUS QUERY FIELD EDITING	

	$query_data = mysql_fetch_array($result);

	$usernumber = $query_data["usernumber"];

	$userid = $query_data["userid"];

	$username = $query_data["username"];

	$usercountry = $query_data["usercountry"];

	$useremail = $query_data["useremail"];

	$userprofile = $query_data["userprofile"];

	$registerdate = $query_data["registerdate"];

	$lastaccesstime = substr($query_data["lastaccesstime"], 0, 4) . '-

' .

				 substr($query_data["lastaccesstime"], 4, 

2) . '-' .

				 substr($query_data["lastaccesstime"], 6, 

2) . ' ' .

				 substr($query_data["lastaccesstime"], 8, 

2) . ':' .

				 substr($query_data["lastaccesstime"], 10, 

2) . ':' .

				 substr($query_data["lastaccesstime"], 12, 

2);

	

	html_header();

	echo "<CENTER><H3>Record for User No.$usernumber - $userid

($username)</H3></CENTER>";



?>

<!-- EDIT AREA -->

<!-- EDIT TABLE HEADERS TO REFLECT TABLE DATA -->

<DIV ALIGN="CENTER">

<TABLE BORDER="1" WIDTH="90%" CELLPADDING="2">

  <TR>

    <TH WIDTH="40%">Country</TH>

    <TD WIDTH="60%"><?php echo $usercountry ?></TD>

  </TR>

  <TR>

    <TH WIDTH="40%">Email</TH>

    <TD WIDTH="60%"><?php echo "<A 

HREF=\"mailto:$useremail\">$useremail</A>"; ?></TD>

  </TR>

  <TR>

    <TH WIDTH="40%">Profile</TH>

    <TD WIDTH="60%"><?php echo $userprofile ?></TD>

  </TR>

  <TR>

    <TH WIDTH="40%">Register Date</TH>

    <TD WIDTH="60%"><?php echo $registerdate ?></TD>

  </TR>

  <TR>

    <TH WIDTH="40%">Last Access Time</TH>

    <TD WIDTH="60%"><?php echo $lastaccesstime ?></TD>

  </TR>

 </TABLE>

 </DIV>

 <?php

	echo "<HR SIZE=\"2\" WIDTH=\"90%\">\n";



//EDIT AREA

//EDIT FOLLOWING QUERY TO REFLECT REAL DATABASE TABLE FIELDS

	$query = "SELECT page, visitcount, accessdate FROM 

$access_log_tablename WHERE userid = '$userid'";

	$result = mysql_query($query);

	if(!$result) error_message(sql_error());

	if(!mysql_num_rows($result))

		echo "<CENTER>No access log record for $userid 

($username).</CENTER>";

	else

		echo "<CENTER>Access log record(s) for $userid 

($username).</CENTER>";

?>

<DIV ALIGN="CENTER">

<TABLE BORDER="1" WIDTH="90%" CELLPADDING="2">

 <TR>

  <TH WIDTH="40%" NOWRAP>Web Page</TH>

  <TH WIDTH="20%" NOWRAP>Visit Counts</TH>

  <TH WIDTH="40%" NOWRAP>Last Access Time</TH>

 </TR>

<?php

	while($query_data = mysql_fetch_array($result))  {

		$page = $query_data["page"];

		$visitcount = $query_data["visitcount"];

		$accessdate = substr($query_data["accessdate"], 0, 4) . '-

' .

				 substr($query_data["accessdate"], 4, 

2) . '-' .

				 substr($query_data["accessdate"], 6, 

2) . ' ' .

				 substr($query_data["accessdate"], 8, 

2) . ':' .

				 substr($query_data["accessdate"], 10, 

2) . ':' .

				 substr($query_data["accessdate"], 12, 2);

		

		echo "<TR>\n";

		echo "<TD WIDTH=\"40%\">$page</TD>\n";

        echo "<TD WIDTH=\"20%\" ALIGN=\"CENTER\">$visitcount</TD>\n";

        echo "<TD WIDTH=\"40%\" ALIGN=\"CENTER\">$accessdate</TD>\n";

        echo "</TR>\n";

    }

?>

 </TR>

</TABLE>

</DIV>

<?php



	}

	

	html_footer();

}



switch($action) {  

	case "view_record":

		view_record();

	break;

	default:

		list_records();

	break;

}

?>



Any help will be appreciated. 
Message #2 by "Nikolai Devereaux" <yomama@u...> on Mon, 11 Feb 2002 17:32:37 -0800

If you're getting the error that the function is not defined, chances are

you're trying to use it before it's defined or included.



It's not clear (to me) from the code you posted whether or not everything's

in the correct order.



shrug (?),



nik



> -----Original Message-----

> From: concepts101@h... [mailto:concepts101@h...]

> Sent: Tuesday, February 12, 2002 1:15 AM

> To: beginning php

> Subject: [beginning_php] undefined function: view_record()

>

>

> I am completely confused why this is happening. Please take a look!

> In chap. 12 when I try to view record I get this error:

> Call to undefined function: view_record() in /userviewer.php on line 236

>

> line 236 is the view_record section of the switch statement:

> switch($action) {

> 	case "view_record":

> 		view_record(); //line #236

> 	break;

> 	default:

> 		list_records();

> 	break;

> Following is my function:

> //VIEW RECORD

> function view_record() {

> 	global $default_dbname, $user_tablename, $access_log_tablename;

> 	global $userid;

> 	global $PHP_SELF;

>

> 	if(empty($userid)) error_message('Empty User ID');

>

> 	$link_id = db_connect($default_dbname);

>

> 	if(!$link_id) error_message(sql_error());

>

> //EDIT AREA

> //EDIT QUERY TO REFLECT REAL DATABASE AND TABLE FIELDS

> 	$query = "SELECT usernumber, userid, username, usercountry,

> useremail, userprofile, registerdate, lastaccesstime FROM $user_tablename

> WHERE userid = '$userid'";

> 	$result = mysql_query($query);

>

> 	if(!$result) error_message(sql_error());

>

> //EDIT AREA

> //EDIT THE FOLLOWING TO REFLECT PREVIOUS QUERY FIELD EDITING

> 	$query_data = mysql_fetch_array($result);

> 	$usernumber = $query_data["usernumber"];

> 	$userid = $query_data["userid"];

> 	$username = $query_data["username"];

> 	$usercountry = $query_data["usercountry"];

> 	$useremail = $query_data["useremail"];

> 	$userprofile = $query_data["userprofile"];

> 	$registerdate = $query_data["registerdate"];

> 	$lastaccesstime = substr($query_data["lastaccesstime"], 0, 4) . '-

> ' .

> 				 substr($query_data["lastaccesstime"], 4,

> 2) . '-' .

> 				 substr($query_data["lastaccesstime"], 6,

> 2) . ' ' .

> 				 substr($query_data["lastaccesstime"], 8,

> 2) . ':' .

> 				 substr($query_data["lastaccesstime"], 10,

> 2) . ':' .

> 				 substr($query_data["lastaccesstime"], 12,

> 2);

>

> 	html_header();

> 	echo "<CENTER><H3>Record for User No.$usernumber - $userid

> ($username)</H3></CENTER>";

>

> ?>

> <!-- EDIT AREA -->

> <!-- EDIT TABLE HEADERS TO REFLECT TABLE DATA -->

> <DIV ALIGN="CENTER">

> <TABLE BORDER="1" WIDTH="90%" CELLPADDING="2">

>   <TR>

>     <TH WIDTH="40%">Country</TH>

>     <TD WIDTH="60%"><?php echo $usercountry ?></TD>

>   </TR>

>   <TR>

>     <TH WIDTH="40%">Email</TH>

>     <TD WIDTH="60%"><?php echo "<A

> HREF=\"mailto:$useremail\">$useremail</A>"; ?></TD>

>   </TR>

>   <TR>

>     <TH WIDTH="40%">Profile</TH>

>     <TD WIDTH="60%"><?php echo $userprofile ?></TD>

>   </TR>

>   <TR>

>     <TH WIDTH="40%">Register Date</TH>

>     <TD WIDTH="60%"><?php echo $registerdate ?></TD>

>   </TR>

>   <TR>

>     <TH WIDTH="40%">Last Access Time</TH>

>     <TD WIDTH="60%"><?php echo $lastaccesstime ?></TD>

>   </TR>

>  </TABLE>

>  </DIV>

>  <?php

> 	echo "<HR SIZE=\"2\" WIDTH=\"90%\">\n";

>

> //EDIT AREA

> //EDIT FOLLOWING QUERY TO REFLECT REAL DATABASE TABLE FIELDS

> 	$query = "SELECT page, visitcount, accessdate FROM

> $access_log_tablename WHERE userid = '$userid'";

> 	$result = mysql_query($query);

> 	if(!$result) error_message(sql_error());

> 	if(!mysql_num_rows($result))

> 		echo "<CENTER>No access log record for $userid

> ($username).</CENTER>";

> 	else

> 		echo "<CENTER>Access log record(s) for $userid

> ($username).</CENTER>";

> ?>

> <DIV ALIGN="CENTER">

> <TABLE BORDER="1" WIDTH="90%" CELLPADDING="2">

>  <TR>

>   <TH WIDTH="40%" NOWRAP>Web Page</TH>

>   <TH WIDTH="20%" NOWRAP>Visit Counts</TH>

>   <TH WIDTH="40%" NOWRAP>Last Access Time</TH>

>  </TR>

> <?php

> 	while($query_data = mysql_fetch_array($result))  {

> 		$page = $query_data["page"];

> 		$visitcount = $query_data["visitcount"];

> 		$accessdate = substr($query_data["accessdate"], 0, 4) . '-

> ' .

> 				 substr($query_data["accessdate"], 4,

> 2) . '-' .

> 				 substr($query_data["accessdate"], 6,

> 2) . ' ' .

> 				 substr($query_data["accessdate"], 8,

> 2) . ':' .

> 				 substr($query_data["accessdate"], 10,

> 2) . ':' .

> 				 substr($query_data["accessdate"], 12, 2);

>

> 		echo "<TR>\n";

> 		echo "<TD WIDTH=\"40%\">$page</TD>\n";

>         echo "<TD WIDTH=\"20%\" ALIGN=\"CENTER\">$visitcount</TD>\n";

>         echo "<TD WIDTH=\"40%\" ALIGN=\"CENTER\">$accessdate</TD>\n";

>         echo "</TR>\n";

>     }

> ?>

>  </TR>

> </TABLE>

> </DIV>

> <?php

>

> 	}

>

> 	html_footer();

> }

>

> switch($action) {

> 	case "view_record":

> 		view_record();

> 	break;

> 	default:

> 		list_records();

> 	break;

> }

> ?>

>



Message #3 by concepts101@h... on Tue, 12 Feb 2002 06:13:34
> 

> If you're getting the error that the function is not defined, chances are

> you're trying to use it before it's defined or included.

> 

> It's not clear (to me) from the code you posted whether or not 

everything's

> in the correct order.

> 

> shrug (?),

> 

> nik

> 

> > -----Original Message-----

> > From: concepts101@h... [mailto:concepts101@h...]

> > Sent: Tuesday, February 12, 2002 1:15 AM

> > To: beginning php

> > Subject: [beginning_php] undefined function: view_record()

> >

> >

> > I am completely confused why this is happening. Please take a look!

> > In chap. 12 when I try to view record I get this error:

> > Call to undefined function: view_record() in /userviewer.php on line 

236

> >

> > line 236 is the view_record section of the switch statement:

> > switch($action) {

> > 	case "view_record":

> > 		view_record(); //line #236

> > 	break;

> > 	default:

> > 		list_records();

> > 	break;

> > Following is my function:

> > //VIEW RECORD

> > function view_record() {

> > 	global $default_dbname, $user_tablename, $access_log_tablename;

> > 	global $userid;

> > 	global $PHP_SELF;

> >

> > 	if(empty($userid)) error_message('Empty User ID');

> >

> > 	$link_id = db_connect($default_dbname);

> >

> > 	if(!$link_id) error_message(sql_error());

> >

> > //EDIT AREA

> > //EDIT QUERY TO REFLECT REAL DATABASE AND TABLE FIELDS

> > 	$query = "SELECT usernumber, userid, username, usercountry,

> > useremail, userprofile, registerdate, lastaccesstime FROM 

$user_tablename

> > WHERE userid = '$userid'";

> > 	$result = mysql_query($query);

> >

> > 	if(!$result) error_message(sql_error());

> >

> > //EDIT AREA

> > //EDIT THE FOLLOWING TO REFLECT PREVIOUS QUERY FIELD EDITING

> > 	$query_data = mysql_fetch_array($result);

> > 	$usernumber = $query_data["usernumber"];

> > 	$userid = $query_data["userid"];

> > 	$username = $query_data["username"];

> > 	$usercountry = $query_data["usercountry"];

> > 	$useremail = $query_data["useremail"];

> > 	$userprofile = $query_data["userprofile"];

> > 	$registerdate = $query_data["registerdate"];

> > 	$lastaccesstime = substr($query_data["lastaccesstime"], 0, 4) . '-

> > ' .

> > 				 substr($query_data["lastaccesstime"], 4,

> > 2) . '-' .

> > 				 substr($query_data["lastaccesstime"], 6,

> > 2) . ' ' .

> > 				 substr($query_data["lastaccesstime"], 8,

> > 2) . ':' .

> > 				 substr($query_data["lastaccesstime"], 10,

> > 2) . ':' .

> > 				 substr($query_data["lastaccesstime"], 12,

> > 2);

> >

> > 	html_header();

> > 	echo "<CENTER><H3>Record for User No.$usernumber - $userid

> > ($username)</H3></CENTER>";

> >

> > ?>

> > <!-- EDIT AREA -->

> > <!-- EDIT TABLE HEADERS TO REFLECT TABLE DATA -->

> > <DIV ALIGN="CENTER">

> > <TABLE BORDER="1" WIDTH="90%" CELLPADDING="2">

> >   <TR>

> >     <TH WIDTH="40%">Country</TH>

> >     <TD WIDTH="60%"><?php echo $usercountry ?></TD>

> >   </TR>

> >   <TR>

> >     <TH WIDTH="40%">Email</TH>

> >     <TD WIDTH="60%"><?php echo "<A

> > HREF=\"mailto:$useremail\">$useremail</A>"; ?></TD>

> >   </TR>

> >   <TR>

> >     <TH WIDTH="40%">Profile</TH>

> >     <TD WIDTH="60%"><?php echo $userprofile ?></TD>

> >   </TR>

> >   <TR>

> >     <TH WIDTH="40%">Register Date</TH>

> >     <TD WIDTH="60%"><?php echo $registerdate ?></TD>

> >   </TR>

> >   <TR>

> >     <TH WIDTH="40%">Last Access Time</TH>

> >     <TD WIDTH="60%"><?php echo $lastaccesstime ?></TD>

> >   </TR>

> >  </TABLE>

> >  </DIV>

> >  <?php

> > 	echo "<HR SIZE=\"2\" WIDTH=\"90%\">\n";

> >

> > //EDIT AREA

> > //EDIT FOLLOWING QUERY TO REFLECT REAL DATABASE TABLE FIELDS

> > 	$query = "SELECT page, visitcount, accessdate FROM

> > $access_log_tablename WHERE userid = '$userid'";

> > 	$result = mysql_query($query);

> > 	if(!$result) error_message(sql_error());

> > 	if(!mysql_num_rows($result))

> > 		echo "<CENTER>No access log record for $userid

> > ($username).</CENTER>";

> > 	else

> > 		echo "<CENTER>Access log record(s) for $userid

> > ($username).</CENTER>";

> > ?>

> > <DIV ALIGN="CENTER">

> > <TABLE BORDER="1" WIDTH="90%" CELLPADDING="2">

> >  <TR>

> >   <TH WIDTH="40%" NOWRAP>Web Page</TH>

> >   <TH WIDTH="20%" NOWRAP>Visit Counts</TH>

> >   <TH WIDTH="40%" NOWRAP>Last Access Time</TH>

> >  </TR>

> > <?php

> > 	while($query_data = mysql_fetch_array($result))  {

> > 		$page = $query_data["page"];

> > 		$visitcount = $query_data["visitcount"];

> > 		$accessdate = substr($query_data["accessdate"], 0, 4) . '-

> > ' .

> > 				 substr($query_data["accessdate"], 4,

> > 2) . '-' .

> > 				 substr($query_data["accessdate"], 6,

> > 2) . ' ' .

> > 				 substr($query_data["accessdate"], 8,

> > 2) . ':' .

> > 				 substr($query_data["accessdate"], 10,

> > 2) . ':' .

> > 				 substr($query_data["accessdate"], 12, 2);

> >

> > 		echo "<TR>\n";

> > 		echo "<TD WIDTH=\"40%\">$page</TD>\n";

> >         echo "<TD WIDTH=\"20%\" ALIGN=\"CENTER\">$visitcount</TD>\n";

> >         echo "<TD WIDTH=\"40%\" ALIGN=\"CENTER\">$accessdate</TD>\n";

> >         echo "</TR>\n";

> >     }

> > ?>

> >  </TR>

> > </TABLE>

> > </DIV>

> > <?php

> >

> > 	}

> >

> > 	html_footer();

> > }

> >

> > switch($action) {

> > 	case "view_record":

> > 		view_record();

> > 	break;

> > 	default:

> > 		list_records();

> > 	break;

> > }

> > ?>

> >

> 



The code is straight out of the book and the switch statement is placed at 

the end as the book says. Is there any other reason besides being defined 

at the wrong place that could cause this?

Thanks,

Dave
Message #4 by concepts101@h... on Tue, 12 Feb 2002 13:52:50
>My apologies, it was simply the lack of a closing bracket "}" that was 

the problem.

 



I am completely confused why this is happening. Please take a look!

> In chap. 12 when I try to view record I get this error:

> Call to undefined function: view_record() in /userviewer.php on line 236

> 

> line 236 is the view_record section of the switch statement:

> switch($action) {  

> 	case "view_record":

> 		view_record(); //line #236

> 	break;

> 	default:

> 		list_records();

> 	break;

> Following is my function:

> //VIEW RECORD

> function view_record() {

> 	global $default_dbname, $user_tablename, $access_log_tablename;

> 	global $userid;

> 	global $PHP_SELF;

> 	

> 	if(empty($userid)) error_message('Empty User ID');

> 	

> 	$link_id = db_connect($default_dbname);

> 	

> 	if(!$link_id) error_message(sql_error());

> 	

> //EDIT AREA

> //EDIT QUERY TO REFLECT REAL DATABASE AND TABLE FIELDS

> 	$query = "SELECT usernumber, userid, username, usercountry, 

> useremail, userprofile, registerdate, lastaccesstime FROM 

$user_tablename 

> WHERE userid = '$userid'";

> 	$result = mysql_query($query);

> 	

> 	if(!$result) error_message(sql_error());

> 

> //EDIT AREA

> //EDIT THE FOLLOWING TO REFLECT PREVIOUS QUERY FIELD EDITING	

> 	$query_data = mysql_fetch_array($result);

> 	$usernumber = $query_data["usernumber"];

> 	$userid = $query_data["userid"];

> 	$username = $query_data["username"];

> 	$usercountry = $query_data["usercountry"];

> 	$useremail = $query_data["useremail"];

> 	$userprofile = $query_data["userprofile"];

> 	$registerdate = $query_data["registerdate"];

> 	$lastaccesstime = substr($query_data["lastaccesstime"], 0, 4) . '-

> ' .

> 				 substr($query_data["lastaccesstime"], 4, 

> 2) . '-' .

> 				 substr($query_data["lastaccesstime"], 6, 

> 2) . ' ' .

> 				 substr($query_data["lastaccesstime"], 8, 

> 2) . ':' .

> 				 substr($query_data["lastaccesstime"], 10, 

> 2) . ':' .

> 				 substr($query_data["lastaccesstime"], 12, 

> 2);

> 	

> 	html_header();

> 	echo "<CENTER><H3>Record for User No.$usernumber - $userid

> ($username)</H3></CENTER>";

> 

> ?>

> <!-- EDIT AREA -->

> <!-- EDIT TABLE HEADERS TO REFLECT TABLE DATA -->

> <DIV ALIGN="CENTER">

> <TABLE BORDER="1" WIDTH="90%" CELLPADDING="2">

>   <TR>

>     <TH WIDTH="40%">Country</TH>

>     <TD WIDTH="60%"><?php echo $usercountry ?></TD>

>   </TR>

>   <TR>

>     <TH WIDTH="40%">Email</TH>

>     <TD WIDTH="60%"><?php echo "<A 

> HREF=\"mailto:$useremail\">$useremail</A>"; ?></TD>

>   </TR>

>   <TR>

>     <TH WIDTH="40%">Profile</TH>

>     <TD WIDTH="60%"><?php echo $userprofile ?></TD>

>   </TR>

>   <TR>

>     <TH WIDTH="40%">Register Date</TH>

>     <TD WIDTH="60%"><?php echo $registerdate ?></TD>

>   </TR>

>   <TR>

>     <TH WIDTH="40%">Last Access Time</TH>

>     <TD WIDTH="60%"><?php echo $lastaccesstime ?></TD>

>   </TR>

>  </TABLE>

>  </DIV>

>  <?php

> 	echo "<HR SIZE=\"2\" WIDTH=\"90%\">\n";

> 

> //EDIT AREA

> //EDIT FOLLOWING QUERY TO REFLECT REAL DATABASE TABLE FIELDS

> 	$query = "SELECT page, visitcount, accessdate FROM 

> $access_log_tablename WHERE userid = '$userid'";

> 	$result = mysql_query($query);

> 	if(!$result) error_message(sql_error());

> 	if(!mysql_num_rows($result))

> 		echo "<CENTER>No access log record for $userid 

> ($username).</CENTER>";

> 	else

> 		echo "<CENTER>Access log record(s) for $userid 

> ($username).</CENTER>";

> ?>

> <DIV ALIGN="CENTER">

> <TABLE BORDER="1" WIDTH="90%" CELLPADDING="2">

>  <TR>

>   <TH WIDTH="40%" NOWRAP>Web Page</TH>

>   <TH WIDTH="20%" NOWRAP>Visit Counts</TH>

>   <TH WIDTH="40%" NOWRAP>Last Access Time</TH>

>  </TR>

> <?php

> 	while($query_data = mysql_fetch_array($result))  {

> 		$page = $query_data["page"];

> 		$visitcount = $query_data["visitcount"];

> 		$accessdate = substr($query_data["accessdate"], 0, 4) . '-

> ' .

> 				 substr($query_data["accessdate"], 4, 

> 2) . '-' .

> 				 substr($query_data["accessdate"], 6, 

> 2) . ' ' .

> 				 substr($query_data["accessdate"], 8, 

> 2) . ':' .

> 				 substr($query_data["accessdate"], 10, 

> 2) . ':' .

> 				 substr($query_data["accessdate"], 12, 2);

> 		

> 		echo "<TR>\n";

> 		echo "<TD WIDTH=\"40%\">$page</TD>\n";

>         echo "<TD WIDTH=\"20%\" ALIGN=\"CENTER\">$visitcount</TD>\n";

>         echo "<TD WIDTH=\"40%\" ALIGN=\"CENTER\">$accessdate</TD>\n";

>         echo "</TR>\n";

>     }

> ?>

>  </TR>

> </TABLE>

> </DIV>

> <?php

> 

> 	}

> 	

> 	html_footer();

> }

> 

> switch($action) {  

> 	case "view_record":

> 		view_record();

> 	break;

> 	default:

> 		list_records();

> 	break;

> }

> ?>

> 

> Any help will be appreciated. 

  Return to Index