Solved

Getting the error of undefined variable while submitting data to database

Posted on 2014-11-14
7
122 Views
Last Modified: 2014-11-15
When i submit the registration form's data it is showing the following error....but the data is inserted in the database while viewing i am getting this error


A PHP Error was encountered

Severity: Notice

Message: Undefined variable: dbRet

Filename: models/registration_model.php

Line Number: 47

Model code

      public function save_registration($un,$email,$pwd,$utype)
    {
      try
      {
      $data = array(
   'username' => $un,
   'password' => $pwd,
   'email' => $email
   
    );
    //print_r($data);
    //die();
    $this->load->database();
    $this->db->reconnect();
    if($utype=='buss')
    {
        $dbRet=$this->db->insert('business', $data);    
    }
    else
    {
        $dbRet-$this->db->insert('user', $data);
    }      
      if (!$dbRet) {
      $ret['ErrorMessage'] = $this->db->_error_message();
      $ret['ErrorNumber'] = $this->db->_error_number();
      log_message('error', "DB Error: (".$ret['ErrorNumber'].") ".$ret['ErrorMessage']);
        $this->db->close();
      return $ret['ErrorNumber'];
        }
        else{
         $rid=$this->db->insert_id();
      $this->db->close();
      return $rid;
        }
      }


As i am new to this please give me the solution
0
Comment
Question by:geetika joshi
  • 3
  • 2
  • 2
7 Comments
 
LVL 36

Accepted Solution

by:
Loganathan Natarajan earned 500 total points
ID: 40444144
This line may be wrong?
$dbRet-$this->db->insert('user', $data);

Open in new window


It should be,

$dbRet = $this->db->insert('user', $data);

Open in new window

0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 40444160
Agreed  ^^^  That will cause the error in the line that follows:

 if (!$dbRet) {
0
 

Author Comment

by:geetika joshi
ID: 40444170
what could be the solution?? as i am new to this please guide me
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 40444174
Replace that line with the one @Loganathan Natarajan showed you above.
0
 

Author Comment

by:geetika joshi
ID: 40444176
okk.....got it done problem solved thank you  both of you

Now i am getting this error

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /home/clubhouzz/public_html/application/controllers/registration.php:17)

Filename: libraries/Session.php

Line Number: 688
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 40444187
You may be printing some where on this file registration.php:17
just comment it. So there won't be any session prob
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 40444194
'session_start' must come before any HTML or text output because it sets a cookie which is part of the 'response headers' that are sent before a web page.  Sounds like you may things in the wrong order.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
A Change in PHP Behavior with Session Write Short Circuit (http://php.net/manual/en/book.session.php#116217) (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
This video teaches users how to migrate an existing Wordpress website to a new domain.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now