Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5
This is the forum to discuss the Wrox book Beginning PHP4 by Wankyu Choi, Allan Kent, Chris Lea, Ganesh Prasad, Chris Ullman; ISBN: 9780764543647
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 10th, 2004, 12:37 AM
Registered User
 
Join Date: Apr 2004
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Fatal error:

Hi, I am a newbiw at php, and i was copying code from "beginner php 4" manual and it seems that the code below has some problem, I keep getting this error:

Fatal error: Call to undefined function: error_message() in c:\inetpub\wwwroot\userviewer.php on line 11

Code below:
-------------------------------------------------------------------
<?php
include "./common_db.inc";
function list_records() {
global $default_dbname, $user_tablename;
global $default_sort_order, $default_order_by, $records_per_page;
global $sort_order, $order_by, $cur_page;
global $PHP_SELF;

$link_id = db_connect($default_dbname);
if(!$link_id) error_message(sql_error());

$query = "SELECT count(*) FROM $user_tablename";

$result = mysql_query($query);
if(!$result) error_message(sql_error());
    
$query_data = mysql_fetch_row($result);
$total_num_user = $query_data[0];
if(!$total_num_user) error_message('No User Found!');
$page_num = $cur_page + 1;

$total_num_page = $last_page_num
                 = ceil($total_num_user/$records_per_page);

html_header();

echo "<CENTER><H3>$total_num_user users found. Displaying the page
                     $page_num out of $last_page_num.</H3></CENTER>\n";

if(empty($order_by)) {
     $order_by_str = "ORDER BY $default_order_by";
     $order_by = $default_order_by;
}
else $order_by_str = "ORDER BY $order_by";
if(empty($sort_order)) {
     $sort_order_str = $org_sort_order = $default_sort_order;
     $sort_order = 'DESC';
}
else {
     $sort_order_str = $org_sort_order = $sort_order;
     if($sort_order == 'DESC') $sort_order = 'ASC';
     else $sort_order = 'DESC';
}

if(empty($cur_page)) {
     $cur_page = 0;
}
     $limit_str = "LIMIT ". $cur_page * $records_per_page .
                                     ", $records_per_page";
$query = "SELECT usernumber, userid, username FROM $user_tablename
                                 $order_by_str $sort_order_str $limit_str";

$result = mysql_query($query);
if(!$result) error_message(sql_error());
?>

<DIV ALIGN="CENTER">
<TABLE BORDER="1" WIDTH="90%" CELLPADDING="2">
<TR>
     <TH WIDTH="25%" NOWRAP>
         <A HREF="<?php echo "$PHP_SELF?action=list_records&
                                 sort_order=$sort_order&
                                 order_by=usernumber"; ?>">
         User Number
         </A>
     </TH>
     <TH WIDTH="25%" NOWRAP>
         <A HREF="<?php echo "$PHP_SELF?action=list_records&
                                     sort_order=$sort_order&
                                     order_by=userid"; ?>">
         User ID
         </A>
     </TH>
     <TH WIDTH="25%" NOWRAP>
         <A HREF="<?php echo "$PHP_SELF?action=list_records&
                                     sort_order=$sort_order&
                                     order_by=username"; ?>">
            User Name
         </A>
     </TH>
     <TH WIDTH="25%" NOWRAP>Action</TH>
</TR>
<?php

while($query_data = mysql_fetch_array($result)) {
     $usernumber = $query_data["usernumber"];
     $userid = $query_data["userid"];
     $username = $query_data["username"];
     echo "<TR>\n";
     echo "<TD WIDTH=\"25%\" ALIGN=\"CENTER\">$usernumber</TD>\n";
     echo "<TD WIDTH=\"25%\" ALIGN=\"CENTER\">$userid</TD>\n";
     echo "<TD WIDTH=\"25%\" ALIGN=\"CENTER\">$username</TD>\n";
     echo "<TD WIDTH=\"25%\" ALIGN=\"CENTER\">
            <A HREF=\"javascript:open_window('$PHP_SELF?action=vi ew_record&
            userid=$userid');\">View Record</A></TD>\n";
     echo "</TR>\n";
}
?>
</TABLE>
</DIV>
<?php
echo "<BR>\n";
echo "<STRONG><CENTER>";
if($page_num > 1) {
     $prev_page = $cur_page - 1;

     echo "<A HREF=\"$PHP_SELF?action=list_records&
                                sort_order=$org_sort_order&
                                order_by=$order_by&cur_page=0\">[Top]</A>";

     echo "<A HREF=\"$PHP_SELF?action=list_records&
                                sort_order=$org_sort_order&
                                order_by=$order_by&
                                cur_page=$prev_page\">[Prev]</A> ";
}
if($page_num < $total_num_page) {
     $next_page = $cur_page + 1;
     $last_page = $total_num_page - 1;

     echo "<A HREF=\"$PHP_SELF?action=list_records&
                                sort_order=$org_sort_order&
                                order_by=$order_by&
                                cur_page=$next_page\">[Next]</A> ";

     echo "<A HREF=\"$PHP_SELF?action=list_records&
                                sort_order=$org_sort_order&
                                order_by=$order_by&
                                cur_page=$last_page\">[Bottom]</A>";
}

echo "</STRONG></CENTER>";
html_footer();
}

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());

$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());
    
$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>";

?>
<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 "\n";
$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;
}
?>
Reply With Quote
  #2 (permalink)  
Old April 10th, 2004, 08:07 AM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Excuse me, this forum is for *Feedback*; this is not where you post your coding problems. You should probably post this problem in the Beginning PHP4 forum under the Books catergory.

Perhaps one of the moderators or administrators will move this thread...?

Thank you.

Snib

P2P Member
<><
Reply With Quote
  #3 (permalink)  
Old April 11th, 2004, 04:14 AM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Cross-post with: http://p2p.wrox.com/topic.asp?TOPIC_ID=12178
Please post replies there.

: )
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compilation FATAL ERROR bouca91 BOOK: Beginning Spring Framework 2 ISBN: 978-0-470-10161-2 1 August 17th, 2008 01:57 PM
Fatal Error - A tough one! gargamel BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 3 April 4th, 2007 04:25 PM
FATAL ERROR. Help me please??? steviej1 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 11 February 27th, 2007 08:05 AM
Fatal Error?? dparsons ASP.NET 1.0 and 1.1 Professional 0 December 18th, 2006 01:55 PM
fatal error!!!! Ashleek007 Beginning PHP 6 October 9th, 2004 10:25 AM



All times are GMT -4. The time now is 09:08 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.