-1

$_GET['name'] -> This line of code is not working as expected

HTML + PHP in one single file

<form action="" method="GET">
        <input onkeyup="onAnyInput(this,'nameTD');" class="w3-input" type="text" name="name" value="<?php echo $f_name ?>">
        <a class="w3-button w3-green" href='updateEmployee.php?sr_no=<?php echo $sr_no ?>&update=true'>Update</a>
</form>




<?php

    if (isset($_GET['update'])) {
        updateEmployee();
      }

    function updateEmployee() {
      global $newName;
      $newName = $_GET['name']; //this line is not working
    }

 ?>
AlamSirji
  • 1
  • 4
  • 1
    You can use isset function `$_GET['name']` on as you are using on $_GET['update'] – Ankur Tiwari Aug 29 '19 at 09:22
  • 2
    Check the existence of `name` param by `isset($_GET['name'])`. – MH2K9 Aug 29 '19 at 09:23
  • I have checked the existence of `name` param by `isset($_GET['name'])` where the value of `$newName` is nothing so what's wrong with the code and why not getting value of input type `name='name'` ? – AlamSirji Aug 29 '19 at 09:54

1 Answers1

0

In your php code you need to put an isset over $_GET['name'] then your code will be looks like:

<?php

if (isset($_GET['update'])) 
{
    updateEmployee();
}

function updateEmployee() 
{
    global $newName;
    if(isset($_GET['name']))
    {
        $newName = $_GET['name']; //this line is not working
    }
 }

?>

Try the above solution will help you

Ankur Tiwari
  • 2,715
  • 2
  • 21
  • 40
  • Now there is no error while executing the code you have suggested but the value of variable '$newName' is nothing why ? – AlamSirji Aug 29 '19 at 09:32