Skip to main content
Topic: "where conditions" at after update (Read 3352 times) previous topic - next topic

"where conditions" at after update

someone help please
so i want to insert my data on other table where the one of my field has "1" value
but the problem is, my data still insert on other table where my field has no "1" value

Code: [Select]
$table_data = array(
    "user_id" => $_POST["id"],
    "name" => $_POST["nama"],
    "status" => $_POST["user_status"]
);

$db->where("user_status",'1');
$bool = $db->insert("tb_name", $table_data);

 

Re: "where conditions" at after update

Reply #1
it is an update you need to do and not insert.
Code: [Select]
$table_data = array(
    "user_id" => $_POST["id"],
    "name" => $_POST["nama"],
    "status" => $_POST["user_status"]
);

$db->where("user_status",'1');
$bool = $db->update("tb_name", $table_data);}

But if mean that you wan to check user_status from post the you can use an if statement.

Code: [Select]
$table_data = array(
    "user_id" => $_POST["id"],
    "name" => $_POST["nama"],
    "status" => $_POST["user_status"]
);
if($_POST["user_status"] == '1') {
    $bool = $db->insert("tb_name", $table_data);
}

Re: "where conditions" at after update

Reply #2

Code: [Select]
$table_data = array(
    "user_id" => $_POST["id"],
    "name" => $_POST["nama"],
    "status" => $_POST["user_status"]
);
if($_POST["user_status"] == '1') {
    $bool = $db->insert("tb_name", $table_data);
}

thanks willvin the second one is what that i mean, and it worked  ;)