Variables related problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Didy
Forum Newbie
Posts: 9
Joined: Mon Feb 27, 2006 6:27 pm

Variables related problem

Post by Didy »

Hello all,

I have following problem and don't know how to fix it:

I want when user open php page to be loaded some data from MySQL datebase to that page , and it is working perfect but i also added two checkboxes for user to check if he wants to upload those data to another datebase and there i have problem.
Because number of entries in datebase is not static so i can't know how much i need fields in the main page, so i decided to use hidden fields and to save there copy of every data that is red from DB, and what i want it is to gave names of the hidden fields from variable. I mean i have while loop which is repeating untill all lines from DB is red (So if i have 5 lines loop will repeat 5 times , and soo on) and every time variable which i use to check if condition is satisfied for while loop is incrised and i want that variable to be name of hidden field and not sure how to make it.
i tried something like this:

Code: Select all

echo "<input name='hidden".$variable."' type='hidden' value='Blablabla'>";
but i get nothing when try to print this hidden field with $_POST["hidden".$variable."]


So pleaseeeee help


Tnx in advance
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

A hidden field is:

Code: Select all

<input name="test" type="hidden" value="" />
Also, try a print_r to see all vars passed :)


Edit: Okay, I swear I just saw type="text" ....caugh, caugh..time to start drinking...
Didy
Forum Newbie
Posts: 9
Joined: Mon Feb 27, 2006 6:27 pm

Post by Didy »

hmm not sure that i following you... :?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Add the following line to see all variables passed via POST:

Code: Select all

echo '<HR><PRE>'; print_r($_POST); echo '</PRE>';
Didy
Forum Newbie
Posts: 9
Joined: Mon Feb 27, 2006 6:27 pm

Post by Didy »

hawleyjr wrote:A hidden field is:


Edit: Okay, I swear I just saw type="text" ....caugh, caugh..time to start drinking...
hahah it was "TEXT" for few second , because i copyed wrong line to make example and then i sow error .... hahah
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Didy wrote:
hawleyjr wrote:A hidden field is:


Edit: Okay, I swear I just saw type="text" ....caugh, caugh..time to start drinking...
hahah it was "TEXT" for few second , because i copyed wrong line to make example and then i sow error .... hahah
It's all good. gave me a reason to open a beer :)
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

hawleyjr wrote:
Didy wrote:
hawleyjr wrote:A hidden field is:


Edit: Okay, I swear I just saw type="text" ....caugh, caugh..time to start drinking...
hahah it was "TEXT" for few second , because i copyed wrong line to make example and then i sow error .... hahah
It's all good. gave me a reason to open a beer :)
Finally someone on the same wave length as me :P
Didy
Forum Newbie
Posts: 9
Joined: Mon Feb 27, 2006 6:27 pm

Post by Didy »

Hey tnx for the help but i think this is not doing job what i need.

So please one more time can you tell me example of one code how to put variable as name of the hiddenfield or text area, or lable and etc... so when i loop it in the while loop i get everytime same object with diferent name.

Tnx
User avatar
chrys
Forum Contributor
Posts: 118
Joined: Tue Oct 04, 2005 9:41 am
Location: West Roxbury, MA (Boston)

Post by chrys »

Umm

Code: Select all

<input type="hidden" name="hiddenvar[var]" value="whatever">
<input type="hidden" name="hiddenvar[var2]" value="whatever">
<input type="hidden" name="hiddenvar[var3]" value="whatever">

<?php

foreach( $_POST['hiddenvar'] as $key=>$val )
     echo "$key = $val";

?>
This?
Didy
Forum Newbie
Posts: 9
Joined: Mon Feb 27, 2006 6:27 pm

Post by Didy »

i am so sorry that i am asking so much stupid questions but simply i can't uderstand what i have to do , even with this foreach i am not sure how to implement it, so i will give you code and please correct it to version that will work as i want:

ok i read informations from DB and counted numbers of rows and store that number to var $numrows and hiergoes code:

Code: Select all

<?php
$i = "0";
while ($i < $numrows) {
echo "<input type='hidden'name='hiddenvar[$i]' value='whatever'> ";
$i++;
}
?>
and now if i want to acces to hiddenfiel number 3 after the loop is finished will i do it like this
$i = "3";
hiddenvar[$i]
User avatar
chrys
Forum Contributor
Posts: 118
Joined: Tue Oct 04, 2005 9:41 am
Location: West Roxbury, MA (Boston)

Post by chrys »

If you want to access it after the form is submitted then it is this:

$_POST['hiddenvar'][3]
Didy
Forum Newbie
Posts: 9
Joined: Mon Feb 27, 2006 6:27 pm

Post by Didy »

It seems that i am too stupid for this , again no results

Code: Select all

<?php
$i = "0";
$numrows = "3";
while ($i < $numrows) {
echo "<input type='hidden'name='hiddenvar[$i]' value='whatever'> ";
$i++;
}
$i = "1";
$blabla = $_POST["hiddenvar"][$i];
echo "".$blabla."";
?>
$i is set to 1 when i echo it because of testing but as you can see it still not working
User avatar
chrys
Forum Contributor
Posts: 118
Joined: Tue Oct 04, 2005 9:41 am
Location: West Roxbury, MA (Boston)

Post by chrys »

I don't really know what you're trying to do.

To access the $_POST variable you need to submit the form, show me all of your code...
Didy
Forum Newbie
Posts: 9
Joined: Mon Feb 27, 2006 6:27 pm

Post by Didy »

Code is too big for forum and because i am not soo good in programing not easy readible.

As i tryed to explain i have datebase with variable numbers of rows (depnds on how much entries members have submited to DB) , and when admin connect to internet and open web page he will get list of all entries
for example:
  • No.-------Name-----------F1----F2------F3-----Accept-----Decline
    1)-------Jim Jonson-------16----Yes-----54------[X] --------- []
    2)-------Kery William-----32----Yes-----18-------[] ----------[X]
    .
    .
    .
    .
    n)-----Mike Evanson---------0------No------9-------[X]-----------[]


    [OK]
[] - representing checkbox

now admin check those that want to accept and when press "OK" button datas from accepted line should be copied to another DB. And i imagine to do that that while populating every single line to make copy of every field to an hiddenfield whic will have name of the line of whose data it is storing.

ok, is it now more clear what i want, sorry i can't spreak and write english wery well so it is why we can't udnerstand each other 8)

P.S. Sorry i tried to make this table as it should be with spaces between fields but forum just merge them, so it is harder to read now
User avatar
chrys
Forum Contributor
Posts: 118
Joined: Tue Oct 04, 2005 9:41 am
Location: West Roxbury, MA (Boston)

Post by chrys »

ok the way I would do that is name the checkboxes like this

accept[id] and deny[id] where id is the id of the record

Then once they submit, you loop through the $_POST['accept'] and $_POST['deny'] and take appropriate action, do you understand?
Post Reply