PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, February 19, 2022

[FIXED] Get true/false codeigniter insert function

 February 19, 2022     codeigniter, codeigniter-4, php, sql     No comments   

Issue

every time I use insert function in my model, the return always true, here's my code

public function insert_text($data)
{
    return $this->db->table($this->table)->insert($data);
}

call code

if ($this->text->insert_text($data)) {
    echo "success";
} else {
    echo "failed";
}

even the execution failed (cause of same primary key already exists), code always return "success", how to fix it?

Thanks


Solution

check if inserted successfuly

if ($this->db->insert_id()) {
    echo "success";
} else {
    echo "failed";
}


Answered By - emppeak
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing