tags:

views:

83

answers:

4

I have a form in index.php

<?php 
  echo '<form action="update_act.php" method="POST">';
  echo '<input type="submit" name="'.$row['act_name'].'" value="edit">
  echo </form>
?>

Here $row['act_name'] is a value fetched from database.

My update_act.php file is

<?php
   echo "Old Activity Name : ".$_POST['$row[\'act_name\']'];
?>

But I am getting an error Undefined index: $row['act_name'] in C:\wamp\www\ps\activity\update_act.php.

I want to have different names for different submits but I am not able to get its value in another page. Is there any way for it?

+3  A: 

I don't exactly know, what you're trying to do, but if the value of variable $row['act_name'] is same in both of the cases (form page and update script), then you can access to that this way:

echo "Old Activity Name : ".$_POST[$row['act_name']];
Radek Šimko
+2  A: 

Use $_POST[$row['act_name']].

Konerak
A: 
   echo "Old Activity Name : ".$_POST['$row[\'act_name\']'];

should be

   echo "Old Activity Name : ".$_POST["$row[act_name]"];

or

   echo "Old Activity Name : ".$_POST[$row[act_name]];
oezi
+2  A: 

PHP only substitutes variables enclosed in double quotes " . What you want is:

echo "Old Activity Name : ". $_POST[$row['act_name']]

But your whole form does not make any sense. The output you get would be:

Old Activity Name : edit

because this is the value of the submit button.

Can you please clarify your question, what do you want to achieve? Here are some thoughts from my side:

Maybe what you want is more like:

<form action="update_act.php" method="POST">;
    <input type="hidden" name="act_name" value="<?php echo $row[act_name] ?>" />
    <input type="submit" name="submit" value="edit">
</form>

// ---- other file ---

<?php
   echo "Old Activity Name : ".$_POST['act_name'];
?>

Why do you want to have different names for different submits ?
Do you want to differentiate between different actions? If so, it is easier you the buttons have the same name and you check against their values, e.g.:

<form action="update_act.php" method="POST">;
    <input type="submit" name="submit" value="edit">
</form>

<form action="update_act.php" method="POST">;
    <input type="submit" name="submit" value="delete">
</form>

and then

<?php 
if($_POST['submit'] == 'edit') {

}
else if ($_POST['submit'] == 'delete') {

}
Felix Kling
I am still getting an error.Here i want to do actually is the data fetched from table $row['act_name'] has to be updated in other page update_act.php and while displaying the old value it gives an error in the update_act.php.
Satish
@Satish: What is the error and how is the value updated? You have no form field that takes a new value.
Felix Kling