If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > help with passing variables from forms to php scripts!!!

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-01-03, 16:41
afarty afarty is offline
Registered User
 
Join Date: Jan 2003
Posts: 13
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>
Reply With Quote
  #2 (permalink)  
Old 03-03-03, 15:28
bcyde bcyde is offline
Registered User
 
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
Reply With Quote
  #3 (permalink)  
Old 03-03-03, 22:25
afarty afarty is offline
Registered User
 
Join Date: Jan 2003
Posts: 13
thanks

i have solved my problem!
$_post[] is the solution!
Reply With Quote
  #4 (permalink)  
Old 03-16-03, 22:36
yreptak yreptak is offline
Registered User
 
Join Date: Mar 2003
Location: Fort Lee, New Jersey
Posts: 1
Passing a variable

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