Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 11th, 2004, 02:12 PM
Registered User
 
Join Date: Apr 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Cannot view a record

Hi, I have managed to get around my previous error. I am now able to view the user_viewer.php file. All users are listed similar to the screenshot in the book on page 446 chp12. However when i click on view record, I cannot view a record. On the bottom left of my screen i have an error.
I get the following error:

Line: 1
Char:1
Error: Object expected
Code:0

I have read the past threads pertaining to this problem, and I cannot understand what to do. So please help me. I have to do a similar assignment for a school project and my deadline is coming up, so please tell me how to fix this example from the book.

 
Old April 12th, 2004, 07:22 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

When you get an error in the bottom-left of the browser, it usually means something is wrong with your JavaScript. I think we will need to see your code.

Snib

P2P Member
<><
 
Old April 12th, 2004, 09:15 PM
Registered User
 
Join Date: Apr 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Snib,
I have highlighted in red, a portion of the code, that i think may have contributed to my error.

Here is my code, its quite long:
BTW, thx for your help really appreciate it.
-------------------------------------------------------------------

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

if(!isset($action))
    $action='list_records';

switch($action) {
   case "view_record":
      view_record();
   break;
   default:
      list_records();
   break;
}
?>



 
Old April 12th, 2004, 09:36 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Ah yes, this does seem to be the trouble-making area....

Is there a JavaScript function called open_window()? Usually the errors 'object expected' and 'object required' mean that you are calling an undefined function.

It looks to me like you can replace it with window.open() or use target=_blank.

Let me know if this does not answer your question.

Snib

P2P Member
<><
 
Old April 12th, 2004, 11:06 PM
Registered User
 
Join Date: Apr 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Snib,
I tried what you suggested and if I change
 <A HREF=\"javascript:open_window('$PHP_SELF?action=vi ew_record&
        userid=$userid');\">View Record</A></TD>\n";
      echo "</TR>\n";
   }

With winodw.open(), a new window pops up with exactly the same information as the previous screen, so in other words i cannot see my users.
 And when i use target=_blank I have no change, the page stays the same.

So I still am not able to see my users, I have downloaded this code from wrox's website in beginning ph4 section chp12, and it seems weird why this pgm isnt working. Please give me more advice to fix this problem.

Thanks a lot.



 
Old April 13th, 2004, 12:44 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Hm.. all I can think of is that you had a typo or two.

This should work:

<A HREF=\"javascript:window.open('$PHP_SELF?action=vi ew_record&
        userid=$userid');\">View Record</A></TD>\n";

Maybe it would be easier if you just made a function called open_window().

Try adding this to your JavaScript code somewhere:

function open_window(url)
{
 window.open(url,' ');
}

Let me know if this works.

Snib

P2P Member
<><
 
Old April 15th, 2004, 04:10 PM
Registered User
 
Join Date: Apr 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Snib,
Well i tried what you said, and there is no change in the data, the window pops up, but i see the exact same page as before.

If there are any other suggestions please let me know.

Thanks!

 
Old April 21st, 2004, 09:18 PM
Registered User
 
Join Date: Apr 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Anybody out there that knows PHP please try to help me with this problem. I need help to get this freaking example to work. I have exhasted all my options, and I conclude that this PHP book sucks!

Please help me if u can.

ThX

 
Old April 22nd, 2004, 11:08 AM
Authorized User
 
Join Date: Dec 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

At the end of your page you have:


if(!isset($action))
    $action='list_records';

switch($action) {
case "view_record":
     view_record();
break;
default:
     list_records();
break;
}
?>


In place of your "if (!isset..." lines I would try putting:


if (isset($_GET['action']))
$action=$_GET['action'];
else
$action='list_records';

if (isset($_GET['userid']))
   $userid=$_GET['userid'];
else
   $userid=null;
 
Old April 22nd, 2004, 12:57 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Maybe you should view the actual string you're passing to javascript. You can either a) view the source of the page and verify that all the PHP variables were substituted properly ($PHP_SELF and $userid), or you can pass the string to alert() instead of window.open().


Oh yeah -- it looks like the code you posted has several newlines in the URL you're passing to window.open(). PLEASE tell me that you did this manually in the text area!! If you try to pass a bad URL to window.open(), you might get an error.

This is a valid URL:
$PHP_SELF?action=view_record&userid=$userid

This is NOT:
$PHP_SELF?action=view_record&
        userid=$userid


Take care,

Nik
http://www.bigaction.org/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent - Send mail with plain view and html view ashish.dadhwal ASP.NET 2.0 Professional 0 November 27th, 2008 01:49 AM
any idea to view xml as it is but in hieratic view seco XSLT 2 January 17th, 2008 08:49 AM
Help Grid View Drop Down List, view all jskinner123 ASP.NET 2.0 Basics 0 November 25th, 2007 06:25 PM
show data record in grid view - sqlserver2005 vinodonline2000 ASP.NET 2.0 Basics 5 August 10th, 2007 05:24 AM
populate details view or list view non empty rows iinfoque ASP.NET 2.0 Basics 0 March 11th, 2007 06:11 AM





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