i am using a function (see below) which contains the following:
-------------------------------------------------------------------------------
"<TD WIDTH=\"25%\" ALIGN=\"CENTER\">
<A HREF=\"javascript:open_window('$PHP_SELF?action=view_record&userid=$userid');\">View Record</A></TD>\n";
--------------------------------------------------------------------------------
further in the script i am using the following:
---------------------------------------------------------------------------------
switch($action) {
case "view_record":
view_record();
break;
default:
list_records();
break;
}
----------------------------------------------------------------------------------
The problem is that i am getting the following message in my browserwindow:
Notice: Undefined variable: action in c:\apache\htdocs\phptest\tmp22lg84h9fb.php on line 228
this is i assume because i am working with php4.2 with register globals off.
and the url with $PHP_SELF is no longer accepted for keeping variables.
in the function i have set GLOBAL $PHP_SELF. I am aware that this no longer works, but despite a lot of time spent on reading php.net online documentation and various forums i can not get it to work. can someone please help? Below is the complete function.
thanks
hansie
THIS IS THE ENTIRE FUNCTION
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=view_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();
Code: Select all