Solved

Getting the error of undefined variable while submitting data to database

Posted on 2014-11-14
7
124 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 83

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 83

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 83

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Foreword (May 2015) This web page has appeared at Google.  It's definitely worth considering! https://www.google.com/about/careers/students/guide-to-technical-development.html How to Know You are Making a Difference at EE In August, 2013, one …
Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

939 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

11 Experts available now in Live!

Get 1:1 Help Now