Weird argument passing problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • redneck_kiwi

    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.dt d">
    <head>
    <title>Internat ional Enterprises, Inc. Depot Level F16 Avionics
    Repair</title>
    </head>

    <body>

    <?
    include('css/header.php');
    include('css/functions.php') ;
    buildhead("Cust omer 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("xxxx xx");
    $query = "SELECT count(*) FROM xxxxxxx";
    $result = mysql_query($qu ery) or trigger_error(" SQL",E_USER_ERR OR);
    $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_p age;

    // 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($sq l) or die("Error reading from database
    reginfo: ".mysql_error() );

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

    <?
    pagethru($pagen o,$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.dt d">
    <head>
    <title>Internat ional Enterprises, Inc. Depot Level F16 Avionics
    Repair</title>

    <meta name="Copyright " content="Copyri ght (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("xxxx xx");
    $sql = "UPDATE xxxxxx SET
    fname='$fname', lname='$lname', coname='$coname ',add1='$add1', add2='$add2',
    city='$city',st ate='$state',zi p='$zip',countr y='$country',ph one='$phone',lo gin='$login',
    email='$email', level='$level' WHERE id=$id";

    $result = mysql_query($sq l) 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("cata log");
    $sql = "SELECT * FROM reginfo WHERE id='$id'";
    $result = mysql_query($sq l) or die("Error retrieving record:
    ".mysql_error() );

    while ($myrow=mysql_f etch_array($res ult)) {
    ?>

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

    <FORM METHOD=post ACTION='custedi t.php'>
    <TABLE CLASS=form BORDER="0">
    <TR>
    <TD ALIGN=center COLSPAN=3>Pleas e edit any items and submit to
    update record</TD>
    </TR>
    <TR><TD></TD></TR>
    <TR>
    <TD ALIGN=right>Fir st Name</TD>
    <TD><INPUT TYPE="text" NAME=fname SIZE=50 VALUE="<?= $myrow['fname']
    ?>"></TD>
    </TR>
    <TR>
    <TD ALIGN=right>Las t Name</TD>
    <TD><INPUT TYPE="text" NAME=lname SIZE=50 VALUE="<?= $myrow['lname']
    ?>"></TD>
    </TR>
    <TR>
    <TD ALIGN=right>Com pany Name</TD>
    <TD><INPUT TYPE="text" NAME=coname SIZE=50 VALUE="<?=
    $myrow['coname'] ?>"></TD>
    </TR>
    <TR>
    <TD ALIGN=right>Add ress</TD>
    <TD><INPUT TYPE="text" NAME=add1 SIZE=50 VALUE="<?= $myrow['add1']
    ?>"></TD>
    </TR>
    <TR>
    <TD ALIGN=right>Add ress</TD>
    <TD><INPUT TYPE="text" NAME=add2 SIZE=50 VALUE="<?= $myrow['add2']
    ?>"></TD>
    </TR>
    <TR>
    <TD ALIGN=right>Cit y</TD>
    <TD><INPUT TYPE="text" NAME=city SIZE=50 VALUE="<?= $myrow['city']
    ?>"></TD>
    </TR>
    <TR>
    <TD ALIGN=right>Sta te</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>Cou ntry</TD>
    <TD><INPUT TYPE="text" NAME=country SIZE=50 VALUE="<?=
    $myrow['country'] ?>"></TD>
    </TR>
    <TR>
    <TD ALIGN=right>Pho ne</TD>
    <TD><INPUT TYPE="text" NAME=phone SIZE=50 VALUE="<?= $myrow['phone']
    ?>"></TD>
    </TR>
    <TR>
    <TD ALIGN=right>Ema il</TD>
    <TD><INPUT TYPE="text" NAME=email SIZE=50 VALUE="<?= $myrow['email']
    ?>"></TD>
    </TR>
    <TR>
    <TD ALIGN=right>Log in</TD>
    <TD><INPUT TYPE="text" NAME=login SIZE=50 VALUE="<?= $myrow['login']
    ?>"></TD>
    </TR>
    <TR>
    <TD ALIGN=right>Acc ess 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="sendemai l" 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

  • Steve

    #2
    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($HT TP_GET_VARS, $HTTP_POST_VARS )
    This makes longer scripts easier to understand.

    Comment

    • porneL

      #3
      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($HT TP_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) ;}

      Comment

      • redneck_kiwi

        #4
        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

        Comment

        Working...