Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases 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 November 23rd, 2004, 08:48 AM
Registered User
 
Join Date: Nov 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default error HREF=$PHP_SELF?action

Hi,
I am a newbie at php, and I was following an example in the php book.

I keep getting an error:

Notice: Undefined variable: action in c:\programmi\easyphp1-7\www\provalibro.php on line 247

help me :(
tanks

Below is the code I used:
--------------------------------------------------------


<?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 November 23rd, 2004, 10:46 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

Hi Brocollo,
First please don't crosspost. If you don't feel your post is descriptive enough to get a response, respond to that post with more information instead of starting a new one. Next, please only post the relevant snips of code, in this case the code at or around line 247 would be sufficient.

Now on to your question, I suspect that you have the register_globals directive turned off, in which case you should use the superglobal $_SERVER['PHP_SELF'] instead of the global $PHP_SELF.

HTH!

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
Reply With Quote
  #3 (permalink)  
Old November 23rd, 2004, 10:49 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

FYI, you can read up on superglobals here: http://www.php.net/manual/en/languag...predefined.php

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
Reply With Quote
  #4 (permalink)  
Old December 2nd, 2004, 07:12 AM
Authorized User
 
Join Date: Oct 2004
Location: Edinburgh, Scotland, United Kingdom.
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to SiliconFuRy
Default


         <A HREF="<?php echo "$PHP_SELF?action=list_records&
                                  sort_order=$sort_order&
                                  order_by=usernumber"; ?>">


Also i strong advise against using variables directly within the string literal of the echo statement, break it off, so that line would become...

<A HREF='<?php echo $_SERVER['PHP_SELF'] . "?action=list_records&sort_order=" . $sort_order . "&order_by=usernumber"; ?>'>

Makes it much easier to handle and watch variables n stuff

Many shoes,

Jamez/SiliconFuRy
Reply With Quote
  #5 (permalink)  
Old December 26th, 2004, 10:07 AM
Registered User
 
Join Date: Dec 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just make sure you go by xhtml standards. with php in html there is really no issues because the output is html.




Everyone who uses a computer needs data recovery. Get a life if you call the 888 number to harass the company. I am the one posting the information. I go around millions of web sites posting information for all companies that pay me. Just delete the post if you feel violated. Thank You bluedevlx@hotmail.com

We recover data files from dead, deleted, formatted, fdisked, corrupted, virus infected, water & fire damaged, downed or inaccessible computer & electronics storage devices: hard disk drives, removable media, optical devices, and tapes.

Very Affordable Service, CALL NOW - 888-275-2684

www.micronixpc.com

Data Recovery in New York City - (888)-275-2684
Reply With Quote
  #6 (permalink)  
Old December 26th, 2004, 10:07 AM
Registered User
 
Join Date: Dec 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Everyone who uses a computer needs data recovery. Get a life if you call the 888 number to harass the company. I am the one posting the information. I go around millions of web sites posting information for all companies that pay me. Just delete the post if you feel violated. Thank You bluedevlx@hotmail.com

Data Recovery New York


Phone Number: (888) 275-2684

Click To View Our Website: http://www.micronixpc.com


Call Us at (888) 275-2684 - We can save your information!.



*We are THE recovery experts!*






We specialize in recovering "lost" data from various types of media including hard drives, floppy disks, digital memory cards, zip disks, jaz disks, CD's, backup tapes and much more. We can also recover your information from nearly any operating system, including Windows XP, 2000, NT, ME, 98, 95, all Mac Operating Systems (OS X, OS 9, OS 8), linux, unix, and many more. Our offices are located in NY. We can help with Data Recovery New York NY. If you are local, call us at (888) 275-2684.




Click To See More Information On Data Recovery New York




Nobody Can Beat Our Service



We Offer Free Pickup and Delivery in Most Areas


Our Successful Recovery Rate Is About 90% On All Media


We Have Very Competitive Recovery Rates (Most are about $500)


We Have A Very Fast Turn Around Time (24-48hrs in most cases)


We Have A Very Knowledgeable Staff


We Have All Of The Equipment Necessary For Any Recovery You May Need


We Help Businesses AND Individuals


Some Of Our Clients Include the NYPD, Columbia University, NYU, Visiting Nurse Service, and many more!




We are here to help you with what you are looking for - data recovery new york
You've come to the right place for data recovery new york.
We have Class 100 Clean Room equipment enabling us to recover data in even some on the most disastrous situations. We would be happy to answer any questions that you may have regarding your media. We can't reliably diagnose any media over the phone, but if you tell us about your situation, we can give you an idea of how likely it may be to recover your files. Data Recovery New York is always avalible for you.





--------------------------------------------------------------------------------

Our Recovery Office Address in NY Is:


Please mail your media to the below address with $100 for the evaluation fee, and your contact information so that we may help you.



Micronixpc

545 Eighth Ave
Suite 401

New York, NY 10018

(888) 275-2684




--------------------------------------------------------------------------------




List Of Recoverable Media (Call Us If Not On List)


Hard Drives (IDE, SCSI, and RAID) - Fujitsu, Maxtor, Quantum, Seagate, IBM, Samsung, Western Digital, And many more.


Flash Media - Secure Digital cards, Smart Media cards, IBM Micro-drives, Secure Digital/Multi-Media Card (SD/MMC), Compact Flash cards, Notebook computers memory cards, laptop cards, MP3 Player cards, PDA's memory, Portable medical equipment media, cell phones memory, digital camera memory cards, photo printers and more.


Tape and Other Backup Media - Optical Drives and Media, DLT Tapes (DLT 260, DLT 600, DLT 2000, DLT 2000XT, DLT 4000, DLT 7000, DLT 8000, DLT 1, SDLT 220) 8mm DAT (8200, 8200C, 8200XL, 8500, 8500C, 8500XL, Mammoth-LT, Mammoth, Mammoth-2) 4mm DAT (DDS, DDS-DC, DDS-2, DDS-3, DDS-4), Floppy Diskettes, SyQuest Cartridges, ¼" Cartridge (QIC Mini format) (DC 2000, DC 2060, DC 2080, DC 2120, DC 2120XL, DC 2120EX, MC 3000, MC 3020, MC 3080, MC 3080 Wide, MC 3095 Wide, Travan 1, Travan 2, Travan 3, Travan 4, Travan 5, Ditto Max 3GB, Ditto Max 5GB, Ditto Max 7GB, Ditto Max 10GB, Aiwa Bolt 6.6 GB, Aiwa Bolt 10GB, Superstation 6.6GB, Superstation 10GB, C4429 - HP 5GB, C4436 - HP 14GB), ¼" Cartridge (QIC Full-size format) (DC 600A, DC 6150, DC 6250, DC 6525, DC 9100, DC 9120, DC 9200, DC 9250, DC 9500, SLR5, SLR24, SLR32, SLR50, SLR100), Iomega Zip, Jaz and Ditto, and any other media type not listed.










--------------------------------------------------------------------------------

If you live in any of the following areas, you are close to our offices:

New York City (NYC), Queens, Brooklyn, Manhattan, Bronx, Staten Island, Long Island (LI), New Jersey (NJ), Astoria, Bayside, Bayswater, Flushing, Beechurst, Bell Harbor, Bellaire, Bellerose, Breezy Point, Briarwood, Broad Channel, Cambria Heights, City Line, College Point, Corona, Cypress Hills, Douglaston, East Elmhurst, East New York, Edgemere, Elmhurst, Far Rockaway, Floral Park, Forest Hills, Fort Tilden, Fresh Meadows, Glen Oaks, Glendale, Hamilton Beach, Long Island, Highland Park, Hillcrest, Hollis, Hollis Hills, Holliswood, Holliswood Estates, NJ, Howard Beach, Jackson Heights, Jamaica, Jamaica Estates, Jamaica Hills, Kensington, Kew Gardens, Kew Gardens Hills, Laurel Hill, Laurelton, Lindenwood, Little Neck, Long Island City, Malba, Maspeth, Middle Village, New Hyde Park, Oakland Gardens, Queens, Ozone Park, Park Slope, Queens Village, Rego Park, Richmond Hill, Ridgewood, Long Island, Rochdale, nyc, Rockaway Park, Rosedale, South Ozone Park, nyc, Seaside, Springfield Gardens, St. Albans, Sunnyside, Wakefield, Whitestone, Woodhaven, New York City, Woodside, Downtown, East Side, Midtown, Upper Manhattan, New Jersey, West Side, Albertson, Atlantic Beach, Baldwin, Baldwin Harbor, Bar Harbor, Bay Park, Bayville, Bellerose Terrace, Bellerose Villages, Bellmore, Bethpage, Biltmore Shores, Brookville, LI, Carle Place, Cedarhurst, nyc, Center Island, Cove Neck, nyc, East Atlantic Beach, East Massapequa, East Rockaway, East Williston, East Hills, East Meadow, East Norwich, Elmont, Farmingdale, Flower Hill, Franklin Square, Freeport, Long Island, Garden City, NYC, Garden City Park, Gibson, Brooklyn, Glen Cove, Glen Head, Glenwood Landing, Great Neck, Greak Neck Estate, Great Neck Plaza, Greenvale, Harbor Green, Harbor Green Estate, Long Island, Harbor Hills, nyc, Harbor Isle, Hempstead, Herricks, Hewlett, Hewlett Bay Park, Hewlett Harbor, Hewlett Neck, Hicksville, Inwood, Jericho, Kings Point, NY, Lake Success, Lakeview, Lattingtown, Laurel Hollow, Lawrence, Levittown, Bronx, Queens, Lido Beach, Locust Grove, Locust Valley, Long Beach, Long Island, Manhattan, Lynbrook, Malverne, Manhasset, in nyc, Manhasset Hills, Manorhaven, Massapequa Park, Massapequa Shores, Matinecock, Meadowmere Park, Merrick, Mill Neck, Mineola, Munsey Park, Muttontown, Nassau Point, Nassau Shores, New Cassel, NY, New Hyde Park, North Hills, Oceanside, Long Island, Old Bethpage, Old Brookville, Old Harbor Green, Plainview, Plainedge, Plandome, Long Island, Plandome Heights, Port Washington, Roslyn, Uniondale, Williamsburg, Bushwick, Brooklyn Heights, Cobble Hill, Red Hook, Carroll Gardens, Fort Greene, nyc, Bedford Stuyvesant, Gowanus, Prospect Heights, Weeksville, Ocean Hill, East New York, Brownsville, Windsor Terrace, Rugby, New Lots, Spring Creek, Sunset Park, Long Island, Long Island, Kensington, Canarsie, Starrett City, nyc, Borough Park, Flatbush, East Flatbush, Midwood, Dyker Heights, Fort Hamilton, Bensonhurst, Ocean Parkway, Marine Park, Mill Basin, nyc, Bath Beach, Gerritsen Beach, Sheepshead Bay, Sea Gate, Coney Island, nyc, Brighton Beach, Manhattan Beach, New York City.



Data Recovery in New York City - (888)-275-2684
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
Chapter 8, href and HRef (p. 285) roman BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 June 16th, 2008 10:40 AM
Request action on change and get no action. Help crussell Ajax 0 September 12th, 2007 11:11 AM
Error Received When Trying to Get Location.Href DragonKing005 Classic ASP Basics 3 May 22nd, 2005 09:54 PM
error in PHP_SELF?action= broccolo PHP Databases 1 November 23rd, 2004 10:47 AM
error in <form action='{$_SERVER['PHP_SELF']} lanita PHP How-To 1 July 27th, 2004 01:07 AM



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


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