problems with textarea and php

0

I have 2 textarea and the user puts several integers and does the search well, the problem is when he places a enter more in the end the program fails, any ideas?

So far so good but then come the possible failures:

Here is how I process the information I receive in textarea .

 $supertoken_id = $_POST['supertoken_id'];
 $num_bug = $_POST['num_bug'];


 if($num_bug!="")
 {
           $onlyconsonants = str_replace("\n", ',',$num_bug);
                   $arregloTokens = explode(",",$onlyconsonants);
                   $longitud=count($arregloTokens);
                   $vowels = array();
                   for ($i=0; $i <$longitud ; $i++) 
                   { 
                     $vowels[$i]=trim($arregloTokens[$i]);
                   }
                   $stringParaIn = implode(",",$vowels);



  //echo "numero de bucc";
    $sql = "select * FROM _tablacompleta WHERE num_bug IN (".$stringParaIn.")";

 $sql2 = "select * FROM _noarribados WHERE num_bug IN (".$stringParaIn.")";

}

if($supertoken_id!="")
{


          $onlyconsonants = str_replace("\n", ',',$supertoken_id);
         $arregloTokens = explode(",",$onlyconsonants);
         $longitud=count($arregloTokens);
         $vowels = array();
         for ($i=0; $i <$longitud ; $i++) 
         { 
           $vowels[$i]=trim($arregloTokens[$i]);
         }
         $stringParaIn = implode(",",$vowels);


            //echo "numero de token";
             $sql = "select * FROM _tablacompleta WHERE supertoken_id IN (".$stringParaIn.")";

           $sql2 = "select * FROM _noarribados WHERE supertoken_id IN (".$stringParaIn.")";

}
    
asked by sanlegas 08.05.2018 в 16:25
source

1 answer

0

Because doing explode() and having an empty line returns an empty string "" , then doing the query pulls error. You could change that explode() for a preg_split() and tell it to return everything except those that are empty. For example:

<?php
  ...
  $onlyconsonants = str_replace("\n", ',',$num_bug);
  $arregloTokens = preg_split("@,@", $onlyconsonants, NULL, PREG_SPLIT_NO_EMPTY);
  ...
    
answered by 08.05.2018 в 16:39