Solved

Getting the error of undefined variable while submitting data to database

Posted on 2014-11-14
7
128 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction ( All good things must come to an end ) The original MySQL API has gone away.  It was deprecated (years ago) by PHP in Version 5.5, and removed from PHP in all current releases .  As a result, the issue is upon us today.  It's time to …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

707 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