Connecting Tech Pros Worldwide Help | Site Map

Weird argument passing problem

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 10:47 AM
redneck_kiwi
Guest
 
Posts: n/a
Default Weird argument passing problem

Hi all:

I have a really weird problem. I am developing a customer catalog
system for my company and as such have delved into sessions for
authentication and access levels. So far, I have managed to get a
working system just about finished.

I am building an interface for our customer service folks to use to
manage registered customers and am seeing some weird behavior.

Basically, the main "my" page calls a page - managecust.php. That page
lists a synopsis of the contents of the users DB and the last cell of
each row contains an 'edit' and 'delete' option.

The edit option is a hyperlink of the type custedit.php?id='xx' where
the 'xx' is the id returned during the initial search of the DB (using
a select * from db).

Theoretically, when the user clicks the edit link beside the
appropriate record, the custedit.php page is called with the id # of
the record being passed.

The weird part is that even though the URL passed is correct, the page
"remembers" which ever record was chosen FIRST.

managecust.php code:
---------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<title>International Enterprises, Inc. Depot Level F16 Avionics
Repair</title>
</head>

<body>

<?
include('css/header.php');
include('css/functions.php');
buildhead("Customer Data Management");
?>

<BR />
<div align="center">

<H3 class=bordered>Customer Data Management</H3>
<BR />

<TABLE CLASS=form BORDER=1 CELLSPACING=2 CELLPADDING=2>
<TR>
<TD>First Name</TD>
<TD>Last Name</TD>
<TD>Company Name</TD>
<TD>Login ID</TD>
<TD>Access Level</TD>
<TD>Options</TD>
</TR>
<?
// Setup pagination so we can browse the data set
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
}

// Count the rows in the DB
connectDB("xxxxxx");
$query = "SELECT count(*) FROM xxxxxxx";
$result = mysql_query($query) or trigger_error("SQL",E_USER_ERROR);
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];

// Calculate the number for $lastpage
$rows_per_page = 15; // We only want 15 rows per page. Adjust to fit
tastes.
$lastpage = ceil($numrows/$rows_per_page);

// Ensure that $pageno is within range
$pageno = (int)$pageno;
if ($pageno < 1) {
$pageno = 1;
} elseif ($pageno > $lastpage) {
$pageno = $lastpage;
} else {
$pageno = $pageno;
}

// Construct the LIMIT clause we will use
$limit = 'LIMIT '.($pageno - 1) * $rows_per_page. ','.$rows_per_page;

// Issue the actual query for data from the DB and process the results
$sql="SELECT * from reginfo ORDER BY lname,fname $limit";
// echo $sql."<BR />";
$result = mysql_query($sql) or die("Error reading from database
reginfo: ".mysql_error());

while($myrow=mysql_fetch_array($result)) {
echo "<TR>";
echo "<TD CLASS=data>".$myrow['fname']."</TD>";
echo "<TD CLASS=data>".$myrow['lname']."</TD>";
echo "<TD CLASS=data>".$myrow['coname']."</TD>";
echo "<TD CLASS=data>".$myrow['login']."</TD>";
echo "<TD CLASS=data>".$myrow['level']."</TD>";
echo "<TD CLASS=data>
<A HREF=custedit.php?id=".$myrow['id'].">Edit</A> |
<A HREF=delcust.php?id=".$myrow['id'].">Delete</A></TD></TR>";
}
?>
</TABLE>
<BR />

<?
pagethru($pageno,$lastpage)?>
</div>
<br />

<? include('css/footer.php'); ?>
</div>
</body>

custedit.php
--------------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<title>International Enterprises, Inc. Depot Level F16 Avionics
Repair</title>

<meta name="Copyright" content="Copyright (c) International
Enterprises, Inc. 2004" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<body>

<?
include('css/header.php');
include('css/functions.php');
buildhead("Edit Customer Information");
?>
<BR />

<?

if ($submit) {
// Connect to the DB and update the record
connectDB("xxxxxx");
$sql = "UPDATE xxxxxx SET
fname='$fname',lname='$lname',coname='$coname',add 1='$add1',add2='$add2',
city='$city',state='$state',zip='$zip',country='$c ountry',phone='$phone',login='$login',
email='$email',level='$level' WHERE id=$id";

$result = mysql_query($sql) or die("Error updating record:
".mysql_error());

if (isset ($_POST['sendemail'])) {
// send a response to the submitter.
$to=$email;
// email message and header stuff here
}

echo '<meta http-equiv="refresh" content="0; URL=managecust.php">"';

} else {
// Connect to the DB and retrieve the record
connectDB("catalog");
$sql = "SELECT * FROM reginfo WHERE id='$id'";
$result = mysql_query($sql) or die("Error retrieving record:
".mysql_error());

while ($myrow=mysql_fetch_array($result)) {
?>

<DIV ALIGN="CENTER">
<H3 CLASS=bordered>Edit Customer Information</H3>
<BR />

<FORM METHOD=post ACTION='custedit.php'>
<TABLE CLASS=form BORDER="0">
<TR>
<TD ALIGN=center COLSPAN=3>Please edit any items and submit to
update record</TD>
</TR>
<TR><TD></TD></TR>
<TR>
<TD ALIGN=right>First Name</TD>
<TD><INPUT TYPE="text" NAME=fname SIZE=50 VALUE="<?= $myrow['fname']
?>"></TD>
</TR>
<TR>
<TD ALIGN=right>Last Name</TD>
<TD><INPUT TYPE="text" NAME=lname SIZE=50 VALUE="<?= $myrow['lname']
?>"></TD>
</TR>
<TR>
<TD ALIGN=right>Company Name</TD>
<TD><INPUT TYPE="text" NAME=coname SIZE=50 VALUE="<?=
$myrow['coname'] ?>"></TD>
</TR>
<TR>
<TD ALIGN=right>Address</TD>
<TD><INPUT TYPE="text" NAME=add1 SIZE=50 VALUE="<?= $myrow['add1']
?>"></TD>
</TR>
<TR>
<TD ALIGN=right>Address</TD>
<TD><INPUT TYPE="text" NAME=add2 SIZE=50 VALUE="<?= $myrow['add2']
?>"></TD>
</TR>
<TR>
<TD ALIGN=right>City</TD>
<TD><INPUT TYPE="text" NAME=city SIZE=50 VALUE="<?= $myrow['city']
?>"></TD>
</TR>
<TR>
<TD ALIGN=right>State</TD>
<TD><INPUT TYPE="text" NAME=state SIZE=50 VALUE="<?= $myrow['state']
?>"></TD>
</TR>
<TR>
<TD ALIGN=right>Zip/Postal Code</TD>
<TD><INPUT TYPE="text" NAME=zip SIZE=50 VALUE="<?= $myrow['zip']
?>"></TD>
</TR>
<TR>
<TD ALIGN=right>Country</TD>
<TD><INPUT TYPE="text" NAME=country SIZE=50 VALUE="<?=
$myrow['country'] ?>"></TD>
</TR>
<TR>
<TD ALIGN=right>Phone</TD>
<TD><INPUT TYPE="text" NAME=phone SIZE=50 VALUE="<?= $myrow['phone']
?>"></TD>
</TR>
<TR>
<TD ALIGN=right>Email</TD>
<TD><INPUT TYPE="text" NAME=email SIZE=50 VALUE="<?= $myrow['email']
?>"></TD>
</TR>
<TR>
<TD ALIGN=right>Login</TD>
<TD><INPUT TYPE="text" NAME=login SIZE=50 VALUE="<?= $myrow['login']
?>"></TD>
</TR>
<TR>
<TD ALIGN=right>Access Level</TD>
<TD>
<SELECT NAME="level">
<OPTION VALUE=99>No Pricing</OPTION>
<OPTION VALUE=1>Base Price</OPTION>
</SELECT>
</TD>
</TR>
<TR>
<TD>Send Credentials via Email</TD>
<TD><INPUT TYPE="checkbox" VALUE="sendemail" NAME="sendemail"></TD>
</TR>
</TABLE>
<?
}
?>

<BR>
<DIV ALIGN="CENTER">
<INPUT TYPE="submit" NAME="submit" VALUE=Update>
<INPUT TYPE="reset" NAME="reset" VALUE=Reset />
</DIV>
</FORM>
<?
}
?>

<br />

<? include('css/footer.php'); ?>
</div>


</body>


Can anyone tell me why this is happening? If I paste the URL directly,
all works well.

TIA

rk


  #2  
Old July 17th, 2005, 10:48 AM
Steve
Guest
 
Posts: n/a
Default Re: Weird argument passing problem

Not sure if this will help, but it is a good idea to combine your GET
and POST vars into an array.

$attributes = array_merge($HTTP_GET_VARS, $HTTP_POST_VARS)
This makes longer scripts easier to understand.

  #3  
Old July 17th, 2005, 10:48 AM
porneL
Guest
 
Posts: n/a
Default Re: Weird argument passing problem

[color=blue]
> Not sure if this will help, but it is a good idea to combine your GET
> and POST vars into an array.
>
> $attributes = array_merge($HTTP_GET_VARS, $HTTP_POST_VARS)
> This makes longer scripts easier to understand.[/color]

or use $_REQUEST, which is a combination of get/post/cookies.

longer scripts rather need to use get/post in one place only,
and use functions or classes for futher operation on acquired data.


--
* html {redirect-to: url(http://browsehappy.pl);}
  #4  
Old July 17th, 2005, 10:48 AM
redneck_kiwi
Guest
 
Posts: n/a
Default Re: Weird argument passing problem

Actually, using $_GET['id'] at the start of the main ELSE structure on
the custedit.php page solved the problem. Thanks to everyone for the
input.

rk

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.