"Undefined index" when quoting an array key
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 the value retrieved from the database.
My file update_act.php
<?php
echo "Old Activity Name : ".$_POST['$row[\'act_name\']'];
?>
But I get an error message 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 can not get its value on another page. Is there any way to do this?
PHP only replaces variables enclosed in double quotes" . Do you want to:
echo "Old Activity Name : ". $_POST[$row['act_name']]
But your whole form makes no sense. You'll get:
Old Activity Name : edit
because it is the value of the submit button.
Can you clarify your question, what do you want to achieve? Here are some thoughts on my part:
, :
<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'];
?>
?
? , , , , :
<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>
<?php
if($_POST['submit'] == 'edit') {
}
else if ($_POST['submit'] == 'delete') {
}