Why is there no way out?

What happened to my code? uniqid()is intended to create a unique code, and it will be stored in the name attribute, then the condition will be indicated, if it is clicked, it will generate its work. Can anyone help me with this? Thanks in advance.

 <html>
    <form method="POST">


    <?php

    $attname = uniqid();

    echo "<input type='submit' name='$attname' class='btn btn-success' value='Post to Peónline'/>";
    echo $attname;
    if(isset($_POST[$attname])){
    echo 'its working';
    }
    ?>
    </form>

    <html>
+4
source share
2 answers

This will not work.

When you refresh the page, the value $attnamewill change. This will happen when you submit the form. Thus, the actual name you are checking will change and will not be the same as the new one $attname.

Put the following after the line echo $attname;:

print_r($_POST);

Also, to work correctly, you need to insert the tag <input>into the tag <form>, for example:

<form method="POST">
<input>...</input>
</form>
+3
source

$attname .

-.

.

...
echo "<input type='hidden' name='elemname' value='<?php echo $attname;?>'/>";
...

,

if (isset($_POST['elemname'])) {
  $elemname = $_POST['elemname'];
  $val = isset($_POST[$elemname]) ? $_POST[$elemname] : '';
  echo $val;
}
0

All Articles