this is the create function as i have added the database class.
id------int
name----var
fname---var
phone---number
i will run here the query which is not valid the (phone) value should be number so i will insert text to have wrong query.
public function create(){
$sql = "Insert into tbl_one (name,fname,phone) values('nameN','nameF',error)";
if($database->query($sql)){
$this->id = $database->insert_id();
} else {
redirect_to('index.php');
}
now here how i can make if the query is false it should redirect me to one page, currently it will show the mysql_error and will give detail why it's wrong but i dont want it i want it just check the query if false redirect me to other page. do i need another function or that where i should get the hint to move on
you have to replace error with 0
public function create(){
$sql = "Insert into tbl_one (name,fname,phone) values('nameN','nameF',0)";
if($database->query($sql)){
$this->id = $database->insert_id();
} else {
redirect_to('index.php');
}
use exception handling
try {
$sql = "Insert into tbl_one (name,fname,phone) values('nameN','nameF',error)";
$database->query($sql);
$this->id = $database->insert_id();
}catch(Exception $e){
//log exception...$e
redirect_to('index.php');
}