Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2003
    Posts
    13

    Unanswered: help with passing variables from forms to php scripts!!!

    help with passing variables from forms to php scripts!!!

    Help!

    I am currently in a fix.
    The situation is this
    1. Page 1 displays a 'BOOKS' table with X numbers of records. Users can select any number of records to edit.
    2. When the user 'submits' in page 1, page2.php will display the selected records for him to edit them.

    My problem is this. When using text box, i set NAME in <INPUT TYPE= NAME= VALUE=...> as "SELECTEDRECORDS[]" to pass to page 2. But when page 2 brings up, it doesn't reflect SELECTEDRECORDS[] to perform my remaining tasks. Why is this so? Is my script wrong? Page 2 shows up but only with the HEADING (NAME,BOOKS ID) and no selected records from page 1. Please help!




    Page 1 script (SeqNum below is the field "sequence number" in the BOOKS table)

    <html>

    <body>

    <?php

    echo "<FORM METHOD=\"POST\" ACTION=\"/PAGE2.php\">";


    $connection = mysql_connect("localhost");
    mysql_select_db ( "BOOKSDB" , $connection );

    $result = mysql_query("SELECT * FROM BOOKS");

    echo "<table>\n";
    echo "<tr><td><strong><P>BOOKS ID</P></strong></td>".
    "<td><strong><P>Name</P></strong></td>".
    "<td><strong><P>Select Records To Edit</P></strong></td>";



    while ($myrow = mysql_fetch_array($result))

    {

    echo "<tr><td><P>{$myrow["BOOKSID"]}</P></td>".
    "<td><P>{$myrow["Name"]}</P></td>".
    "<td><P><INPUT TYPE=\"checkbox\" NAME= \"SELECTEDRECORDS[]\" VALUE={$myrow["SeqNum"]}></P></td></tr>";

    }


    echo"</table>\n";
    echo"<INPUT TYPE=\"submit\" VALUE=\"CONFIRM\">";

    echo"<INPUT TYPE=\"reset\">";
    echo"</form>";
    ?>
    </body>
    </html>



    Page 2 Script

    <html>

    <body>

    <?php

    $connection = mysql_connect("localhost");
    mysql_select_db ( "BOOKSDB" , $connection );

    $count=count($SELECTEDRECORDS);

    echo "<FORM METHOD=\"POST\" ACTION=\"displayedittedvalues.php\">";
    echo "<table>\n ";

    echo "<tr><td><strong><P>BOOK ID</P></strong></td>".
    "<td><strong><P>Name</P></strong></td></TR>";

    $index = 0;

    for ($i=0; $i<$count; $i++) {

    $result = mysql_query("SELECT * from BOOKSDB WHERE SeqNum= $SELECTEDRECORDS[$i] ");
    while ($myrow = mysql_fetch_array($result))
    {

    $NameStr = Name.$index;
    $BookIDStr = BOOKSID.$index;

    echo "<tr><td><P><INPUT TYPE=\"TEXT\" NAME= $NameStr VALUE={$myrow["Name"]}></P></td>".
    "<td><P><INPUT TYPE=\"text\" NAME= $BookIDStr VALUE={$myrow["BOOKSID"]}></P></td></tr>";

    $index++;
    }

    }


    echo "</table>";
    echo "</FORM>";

    ?>


    </body>
    </html>

  2. #2
    Join Date
    Dec 2002
    Posts
    65
    Are you checking the value of count on page 2? What does it come up with? You may also want to check if register_globals is on if you're going to try and access $SELECTEDRECORDS like that instead of using $_POST['SELECTEDRECORDS'] .

    Hope this helps.

    -b
    (I'm only available at the email address provided in my profile on weekdays, if you have questions or advice, during off hours use AIM). Also any views I provide here or on my website are mine and not representative of any views of my work, family, friends and sometimes even myself.

    http://www.bcyde.com

  3. #3
    Join Date
    Jan 2003
    Posts
    13
    thanks

    i have solved my problem!
    $_post[] is the solution!

  4. #4
    Join Date
    Mar 2003
    Location
    Fort Lee, New Jersey
    Posts
    1

    Passing a variable

    Originally posted by afarty
    thanks

    i have solved my problem!
    $_post[] is the solution!
    Actually this is not best, because you should know what method is in <FORM : GET/POST.
    BEST way is
    @import_request_variables('pg', '');

    Now you will have a variable with same name that form has and it will automatically recognize GET/POST method.

    Even if you have GET and POST together it will overwrite POST variables by GET variable (pg in parameters);

    Good luck.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •