{"id":810,"date":"2022-08-30T15:07:33","date_gmt":"2022-08-30T15:07:33","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/undefined-variable-codeigniter-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:07:33","modified_gmt":"2022-08-30T15:07:33","slug":"undefined-variable-codeigniter-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/undefined-variable-codeigniter-collection-of-common-programming-errors\/","title":{"rendered":"Undefined variable Codeigniter-Collection of common programming errors"},"content":{"rendered":"<p>I have this error on my view and i can&#8217;t find where is the problem<\/p>\n<blockquote>\n<p>A PHP Error was encountered<\/p>\n<p>Severity: Notice<\/p>\n<p>Message: Undefined variable: errors<\/p>\n<p>Filename: views\/register_user.php<\/p>\n<p>Line Number: 5<\/p>\n<\/blockquote>\n<p>view:<\/p>\n<pre><code>\n\n\n\n\n<\/code><\/pre>\n<p>and here controller<\/p>\n<pre><code>function register(){\n    if($_POST){\n        $config=array(\n            array(\n                'field'=&gt;'username',\n                'label'=&gt;'Username',\n                'rules'=&gt;'trim|required|min_length[3]|is_unique[users.username]'\n                ),\n            array(\n                'field'=&gt;'password',\n                'label'=&gt;'Password',\n                'rules'=&gt;'trim|required|min_length[5]|max_length[15]'\n                ),\n            array(\n                'field'=&gt;'password2',\n                'label'=&gt;'Password Confirmed',\n                'rules'=&gt;'trim|required|min_length[5]|matches[password]'\n                ),\n            array(\n                'field'=&gt;'user_type',\n                'label'=&gt;'User Type',\n                'rules'=&gt;'required'\n                ),\n            array(\n                'field'=&gt;'email',\n                'label'=&gt;'Email',\n                'rules'=&gt;'trim|required|is_unique[users.email]|valid_email'\n                )\n            );\n        $this-&gt;load-&gt;library('form_validation');\n        $this-&gt;form_validation-&gt;set_rules($config);\n        if($this-&gt;form_validation-&gt;run() == FALSE){\n            $data['errors']=validation_errors();\n        } else {\n        $data=array(\n            'username'=&gt;$_POST['username'],\n            'password'=&gt;$_POST['password'],\n            'user_type'=&gt;$_POST['user_type']\n            );\n        $this-&gt;load-&gt;model('user');\n        $userid=$this-&gt;user-&gt;create_user($data);\n        $this-&gt;session-&gt;set_userdata('userID',$userid);\n        $this-&gt;session-&gt;set_userdata('user_type',$_POST['user_type']);\n        redirect(base_url().'posts');\n    }\n}\n    $this-&gt;load-&gt;helper('form');\n    $this-&gt;load-&gt;view('header');\n    $this-&gt;load-&gt;view('register_user');\n    $this-&gt;load-&gt;view('footer');\n}\n<\/code><\/pre>\n<p>i&#8217;m starting using Codeigniter and i can&#8217;t find the problem&#8230;<\/p>\n<ol>\n<li>\n<p>Change this:<\/p>\n<pre><code>\n\n\n\n\n<\/code><\/pre>\n<p><strong>UPDATE:<\/strong> But you have a lot of other problems in your code. You need to clear it. For example: You didn&#8217;t load the errors. And you let to create user without validation.<\/p>\n<\/li>\n<li>\n<p>Please try this<\/p>\n<pre><code>\n\n\n\n\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 22:46:58. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have this error on my view and i can&#8217;t find where is the problem A PHP Error was encountered Severity: Notice Message: Undefined variable: errors Filename: views\/register_user.php Line Number: 5 view: and here controller function register(){ if($_POST){ $config=array( array( &#8216;field&#8217;=&gt;&#8217;username&#8217;, &#8216;label&#8217;=&gt;&#8217;Username&#8217;, &#8216;rules&#8217;=&gt;&#8217;trim|required|min_length[3]|is_unique[users.username]&#8217; ), array( &#8216;field&#8217;=&gt;&#8217;password&#8217;, &#8216;label&#8217;=&gt;&#8217;Password&#8217;, &#8216;rules&#8217;=&gt;&#8217;trim|required|min_length[5]|max_length[15]&#8217; ), array( &#8216;field&#8217;=&gt;&#8217;password2&#8217;, &#8216;label&#8217;=&gt;&#8217;Password Confirmed&#8217;, &#8216;rules&#8217;=&gt;&#8217;trim|required|min_length[5]|matches[password]&#8217; ), [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-810","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/810","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=810"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/810\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}