Organizational Research By

Surprising Reserch Topic

undefined index in zend framework


undefined index in zend framework  using -'php,zend-framework'

Here is my simple form:

<form action = "input" method = "POST">
Name: <input type="text" name="uname"/> <br>
<input type="submit" name="button" value="hit it" >
</form>


Here is my controller:

public function indexaction()
{
    $db= new DataBase();
    $db->initDB("testform", "benjaminsform");
    $con=mysqli_connect("localhost","root","","benjaminsform");
    if($_SERVER["REQUEST_METHOD"]=="POST"){
        if(isset($_POST["button"])) {
            $uname=$_POST['uname'];
        }
        $success=$db->insert(array("name"=>$uname));
    }

    return array();
}


And this is the error im receiving"


  Notice: Undefined variable: uname in /usr/local/zend/var/apps/http/v-hrswebapps/80/benjamintestapp/1.0.0_201/module/Application/src/Application/Controller/IndexController.php on line 27
  
  Line 27 the one in question is the $success statement.


Ive tried working with my isset statements but nothing is really passing into the array.
    

asked Oct 23, 2015 by rajeshujade
0 votes
2 views



Related Hot Questions

1 Answer

0 votes

You can do this to get the post data

public function indexaction()
{
   $request = $this->getRequest();
   if ($request->isPost()){
      $params = $request->getPost();
      $uname = $params['uname'];
   }
}

But it seems like your action is input but your code is under indexaction that's why it is not getting your postdata

answered Oct 23, 2015 by sameer rathore

...