I insert a row with following commands :
create.php
<?php
require_once 'db_connect.php';
if($_POST) {
$validator = array('success' => false, 'messages' => array());
$a = $_POST['id'];
$b = $_POST['number'];
$sql = "INSERT INTO class (id, number)
SELECT '$a', '$b'
WHERE EXISTS (SELECT * FROM members WHERE idmember = $a AND active = 1)";
$query = $connect->query($sql);
if($query === TRUE) {
$validator['success'] = true;
$validator['messages'] = "Message : OK!";
} else {
$validator['success'] = false;
$validator['messages'] = "Message : ERROR!";
}
$connect->close();
echo json_encode($validator);
}
When I add a field to this table, that active is = 1, i do not have a problem and the row is added. When I add a field to this table, that active is = 0, The row will not be added to the database mysql, But "Message : OK!" is shown. why?