There is an array of data that the cycle then adds to the database, but by-passing that there is not some data, respectively, this part of the array is excluded.

if ($_GET['addvid'] == "leadadd") { $json_output = array(); if (isset($_POST['name_lead'])) {$name = checkrequest(iconv("UTF-8", "WINDOWS-1251", $_POST['name_lead']));} if (isset($_POST['phone_lead'])) {$phone = $_POST['phone_lead'];} if (isset($_POST['email_lead'])) {$email = checkrequest($_POST['email_lead']);} if (isset($_POST['channel_lead'])) {$source = checkrequest($_POST['channel_lead']);} if (isset($_POST['status_lead'])) {$status = checkrequest($_POST['status_lead']);} if (isset($_POST['address_lead'])) {$address_lead = checkrequest(iconv("UTF-8", "WINDOWS-1251", $_POST['address_lead']));} if (isset($_POST['comment_lead'])) {$comment_lead = checkrequest(iconv("UTF-8", "WINDOWS-1251", $_POST['comment_lead']));} if (isset($_POST['group_lead'])) {$id_group = checkrequest($_POST['group_lead']);} if (isset($_POST['name_lead']) or isset($_POST['phone']) or isset($_POST['email_lead'])) { /* то можно занести информацию */ $id_c = $myrow_cabinet['id']; $id_staff = $userdata['id_staff']; $result_status = mysql_query("SELECT id FROM status WHERE id = '".$status."' and id_cabinet = '$id_c'"); $myrow_status = mysql_fetch_array($result_status); $dates = date('Ymd H:i:s', time()); $add_vid = "hand"; $result = mysql_query("INSERT INTO lids (id_cabinet,id_staff,name,tel,id_type,email,source,comment,address,status,status_view,add_vid,datetime) VALUES ('$id_c','$id_staff','$name','$phone','$id_group','$email','$source','$comment_lead','$address_lead','$myrow_status[id]','1','$add_vid','$dates')"); $id_new_lead = mysql_insert_id(); if ($result == 'true') { $json_output = array('succes'=>1, 'url_new_lead'=>'/'.$id_c.'/leads/details-'.$id_new_lead.'', 'msg'=>'<div class="lead-add-success"><div class="ucrmicon success-img">Q</div></div>'); // Добавление названий форм $lead_add = array( array("vid_change" => "add", "coment_change" => "Добавлен клиент", "change_old" => "", "change_new" => ""), array("vid_change" => "name", "coment_change" => "", "change_old" => "", "change_new" => "$name"), array("vid_change" => "phone", "coment_change" => "", "change_old" => "", "change_new" => "$phone"), array("vid_change" => "email", "coment_change" => "", "change_old" => "", "change_new" => "$email"), array("vid_change" => "address", "coment_change" => "", "change_old" => "", "change_new" => "$address_lead"), array("vid_change" => "comment", "coment_change" => "$comment_lead", "change_old" => "", "change_new" => ""), array("vid_change" => "status", "coment_change" => "", "change_old" => "", "change_new" => "$myrow_status[id]"), array("vid_change" => "group", "coment_change" => "", "change_old" => "", "change_new" => "$id_group") ); for ($i = 0; $i < count($lead_add); $i++) { $item = $lead_add[$i]; $date = date('Ymd H:i:s', time()); $vid_change = $lead_add[$i]['vid_change']; $coment_change = $lead_add[$i]['coment_change']; $change_old = $lead_add[$i]['change_old']; $change_new = $lead_add[$i]['change_new']; mysql_query("INSERT INTO change_history (id_lid,datetime,vid_change,coment_change,change_old,change_new,id_staff,id_cabinet) VALUES ('$id_new_lead','$date','$vid_change','$coment_change','$change_old','$change_new','$id_staff','$id_c')"); } } else { $json_output = array("succes"=>0, "msg"=>"<div class='lead-add-error'><div class='ucrmicon error-img'>N</div>Что-то не работает, сообщите в тех.поддержку!</div>"); } } else {$json_output = array("succes"=>0, "msg"=>"<div class='lead-add-error'><div class='ucrmicon error-img'>N</div>Вы не заполнили обязательные поля!</div>");} echo json_encode($json_output); exit; } 

Those. for example, it was not specified in the email form, it means array("vid_change" => "email", "coment_change" => "", "change_old" => "", "change_new" => "$email"), does not participate in array formation ...

How to do this?

    1 answer 1

    An "vid_change"=> "address" with "vid_change"=> "address" will not exist, because $ address variable is not specified.

     <?php $add = "test"; $name = "test"; $phone = "test"; $email = "test"; $comment = "test"; $status = "test"; $group = "test"; $lead_add = array( array("vid_change" => "add", "coment_change" => "Добавлен клиент", "change_old" => "", "change_new" => ""), array("vid_change" => "name", "coment_change" => "", "change_old" => "", "change_new" => "$name"), array("vid_change" => "phone", "coment_change" => "", "change_old" => "", "change_new" => "$phone"), array("vid_change" => "email", "coment_change" => "", "change_old" => "", "change_new" => "$email"), array("vid_change" => "address", "coment_change" => "", "change_old" => "", "change_new" => "$address_lead"), array("vid_change" => "comment", "coment_change" => "$comment_lead", "change_old" => "", "change_new" => ""), array("vid_change" => "status", "coment_change" => "", "change_old" => "", "change_new" => "$myrow_status[id]"), array("vid_change" => "group", "coment_change" => "", "change_old" => "", "change_new" => "$id_group") ); for($i = 0; $i < count($lead_add); $i++) { $item = $lead_add[$i]; if(!isset($$item["vid_change"])) { unset($lead_add[$i]); } } sort($lead_add); print_r($lead_add); ?> 
    • doesn't work ... adds anyway ... - Alexander Sizintsev
    • you have a variable does not exist or there is simply no value? if there is a variable but no value, change !isset($$item["vid_change"]) to mb_strlen($$item["vid_change"], "UTF-8") == 0 - ikerya
    • My variable can be both a number and a text - Alexander Sizintsev
    • I added the full code as I had it ... what to do so that those variables that did not come or did not come but were empty ... I was exhausted ... - Alexander Sizintsev
    • one
      @AlexanderSizintsev is not for that :) if you have a solution, you can answer the answer as the correct one - ikerya