hey I'm having a problem trying to get some variables passed on a form to another page where the processing is handled.

basically what I'm trying to do is display the titles of pages from a website that are stored on a mysql database. those titles are passed thru a variable, which is used for the name and value in the html form.

I used a loop to display the values, passing each element to a variable in php, which is coded as such for the value and name of each page title. This way no matter how many pages are added or removed in the future, I don't have to go back and manually display all pages - it just pulls the titles from a database and assigns a numeric value to them in an array.

Here is what I'm getting at, because I'm sure I'm not explaining this correctly.

...code from above

$pageName = mysql_query("select `pageName` from pages");

if(!$pageName) 
 {  
  echo "ERROR: $pageName query invalid in editMain.php <br/>";  
  mysql_close();  
  exit(); 
 }

$rows = mysql_num_rows($pageName);
$i = 0;

while($i < $rows)
{
 while($getPageName=mysql_fetch_array($pageName))
 {
  ?>
  <tr>
  <td align="left">
  <?php echo $getPageName['pageName'];?>
  </td>
  <td align="right">
  <input type="radio" value="<?php $getPageName['pageName'];?>" name="<?php $getPageName['pageName'];?>">
  </td>
  </tr>
  <?php
  $i++;
 }
}

and so on and so forth for the rest of the code. I'm trying to pass $getPageName into the values and names of the radio buttons - so for instance, if one of the pages is named main, that element of the array ($getPageName) will be assigned Main for the first round of the loop.

My problem is getting the next page to carry that variable over (the value of the variable changes due to the user deciding which page he/she wants to edit) and assign it to the $var = $_POST assignment on the page that handles the form processing.

so I guess my ultimate question is on the next page when I try to pull the choice the user selected, how do I pull that variable using post?

it would be something like: $title = $_POST[$getPageName['pageName']']; but I know that syntax is wrong - I got an error when I tried to run it. That's kinda where I'm stuck.

if anyone understands what I'm getting at, can you please let me know what I'm doing wrong?

I know you can also pass variables thru session handling, but since I am trying to do this strictly in php, the page the user chooses isn't set in stone until after the form is submitted. I don't think it's possible to assign a variable like that to a session variable after the form has been submitted.

hey I'm having a problem trying to get some variables passed on a form to another page where the processing is handled.

basically what I'm trying to do is display the titles of pages from a website that are stored on a mysql database. those titles are passed thru a variable, which is used for the name and value in the html form.

I used a loop to display the values, passing each element to a variable in php, which is coded as such for the value and name of each page title. This way no matter how many pages are added or removed in the future, I don't have to go back and manually display all pages - it just pulls the titles from a database and assigns a numeric value to them in an array.

Here is what I'm getting at, because I'm sure I'm not explaining this correctly.

...code from above

$pageName = mysql_query("select `pageName` from pages");

if(!$pageName) 
 {  
  echo "ERROR: $pageName query invalid in editMain.php <br/>";  
  mysql_close();  
  exit(); 
 }

$rows = mysql_num_rows($pageName);
$i = 0;

while($i < $rows)
{
 while($getPageName=mysql_fetch_array($pageName))
 {
  ?>
  <tr>
  <td align="left">
  <?php echo $getPageName['pageName'];?>
  </td>
  <td align="right">
  <input type="radio" value="<?php $getPageName['pageName'];?>" name="<?php $getPageName['pageName'];?>">
  </td>
  </tr>
  <?php
  $i++;
 }
}

and so on and so forth for the rest of the code. I'm trying to pass $getPageName into the values and names of the radio buttons - so for instance, if one of the pages is named main, that element of the array ($getPageName) will be assigned Main for the first round of the loop.

My problem is getting the next page to carry that variable over (the value of the variable changes due to the user deciding which page he/she wants to edit) and assign it to the $var = $_POST assignment on the page that handles the form processing.

so I guess my ultimate question is on the next page when I try to pull the choice the user selected, how do I pull that variable using post?

it would be something like: $title = $_POST[$getPageName['pageName']']; but I know that syntax is wrong - I got an error when I tried to run it. That's kinda where I'm stuck.

if anyone understands what I'm getting at, can you please let me know what I'm doing wrong?

I know you can also pass variables thru session handling, but since I am trying to do this strictly in php, the page the user chooses isn't set in stone until after the form is submitted. I don't think it's possible to assign a variable like that to a session variable after the form has been submitted.

Dear sleign,
I just look out your code. you done a mistake in
<input type="radio" value="<?php $getPageName;?>" name="<?php $getPageName;?>"> this code.
you assign the value and name using echo. like
<input type="radio" value="<?php echo $getPageName;?>" name="<?php echo $getPageName;?>">
it will run. and use this
$title = $_POST[$getPageName];
try it.
Regards,
Durai

Dear sleign,
I just look out your code. you done a mistake in
<input type="radio" value="<?php $getPageName;?>" name="<?php $getPageName;?>"> this code.
you assign the value and name using echo. like
<input type="radio" value="<?php echo $getPageName;?>" name="<?php echo $getPageName;?>">
it will run. and use this
$title = $_POST[$getPageName];
try it.
Regards,
Durai

Hi,

Your code :
<input type="radio" value="<?php $getPageName;?>" name="<?php $getPageName;?>"

Update this code to:

<input type="radio" value="<?php echo $getPageName;?>" name="<?php echo $getPageName;?>"

your are not echo value from the database;

Thanks,
Ranjeet :)

make 2 php files page1.php & page2.php...

page1.php
- - -

<?php 
$query = mysql_query("select `pageName` from pages");
?>
<form method="post" action="page2.php">
<?php 
while ($getPageName= mysql_fetch_array($query))
{?>
<input type="radio" value="<?php echo $getPageName['pageName'];?>" name="pagename"><?php
}
?>
<input type="submit" value="goto next page">
</form>

page2.php
- - -

<?php
$pagename = $_POST['pagename'];
echo $pagename;
?>

yea I shoulda remembered the echo command, but I updated the loop using echo to assign a name/value to the radio button and it's still not passing onto the next form - any other ideas?

my code for this part is:

$pageName = mysql_query("select `pageName` from pages");

$rows = mysql_num_rows($pageName);
$i = 0;

while($i < $rows)
{
 while($getPageName=mysql_fetch_array($pageName))
 {
  ?>
  <tr>
  <td align="left">
  <?php echo $getPageName['pageName'];?>
  </td>
  <td align="right">
  <input type="radio" value="<?php echo $getPageName['pageName'];?>" name="<?php echo $getPageName['pageName'];?>">
  </td>
  </tr>
  <?php
  $i++;
 }
}
?>

<tr>
<br/>
<td><input type="submit" name="submit" value="Submit"></td>
<td align=right><input type="reset" name="reset" value="Reset"></td>
</tr>

</table>
</form>
</div>

<?php mysql_close();?>

and to catch it on the next page I have:

<?php

$main = $_POST[$getPageName['pageName']];

$about = $_POST[$getPageName['pageName']];

$code = $_POST[$getPageName['pageName']];

$threads = $_POST[$getPageName['pageName']];

$contact = $_POST[$getPageName['pageName']];

$resume = $_POST[$getPageName['pageName']];
?>

I tried to do the same thing in the past and I gave up on it, but since it's come up again I'm bound and determined to get this to work. I can see this as being really useful in a lot of places if I can get this code to work, but for some reason it just doesn't pass. I don't know what I'm overlooking, but it's gotta be something.

I do know that the loop is functional because it will display the page titles like it's supposed to, but it just flat out refuses to pass those names onto the next form...

Sajif THANK YOU - you are GOD!

It worked beautifully - now all I gotta do is work that code into my script - thank u thank u thank u :)

hey man.. see this line of ur code

<input type="radio" value="<?php echo $getPageName['pageName'];?>" name="<?php echo $getPageName['pageName'];?>">

here u r trying to assign dynamic value for "name"..
suppose u r in the 1st loop..., let the page name be "mypage1"
ur code would now be like this...

<input type="radio" value="mypage1" name="mypage1">

similarly in the subsequent loops, it would be...,

<input type="radio" value="mypage1" name="mypage1">
<input type="radio" value="mypage2" name="mypage3">
<input type="radio" value="mypage2" name="mypage3">
...
...

Now, wen u try to receive these values like what u did in ur next page, wat happens is u get only the final value for all the variables... u get $main = "name of last page" , $about= "name of last page" , ...

so u'll have to do like this..

$main = $_POST['mypage1'];
$about = $_POST['mypage2'];
$code = $_POST['mypage3'];
...
...

which'll a useless code rite...!

i suggest u try this....,

...
...
$pageName = mysql_query("select `pageName` from pages");
$i=0;
while($getPageName=mysql_fetch_array($pageName))
{
  ?>
  <tr>
  <td align="left">
  <?php echo $getPageName['pageName'];?>
  </td>
  <td align="right">
  <input type="radio" value="<?php echo $getPageName['pageName'];?>" name="<?php echo "mypage".$i;?>">
  </td>
  </tr>
  <?php
  $i++;
}
?>

next page...

<?php
$main = $_POST['mypage1'];
$about = $_POST['mypage2'];
...
...
?>

hope u'll get a good understanding of dynamic form...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.