title: Insert values from function php in database mysql
body: <p>im testing insert al ip's from an array created with one function in php, in one database..</p>
  
  <p>I have this code: </p>
  
  <pre><code>&lt;?php
  
  //Funcion IP
  $range='192.168.3.0/24';
  
  function rango($range){
      $parts = explode('/',$range);
      $exponent = 32-$parts[1].'-';
      $count = pow(2,$exponent);
      $start = ip2long($parts[0]);
      $end = $start+$count;
      return array_map('long2ip', range($start+1, $end-2) );
  }
  
  
  
  //Conexion a la Base de datos
  $mysqli = new mysqli("localhost", "root", "", "ips");
  if ($mysqli-&gt;connect_errno) {
      echo "Falló la conexión con MySQL: (" . $mysqli-&gt;connect_errno . ") " . $mysqli-&gt;connect_error;
  }
  
  //Elimina la tabla si existe
  if (!$mysqli-&gt;query("DROP TABLE IF EXISTS prueba3") ||
      //Crea la tabla
      !$mysqli-&gt;query("CREATE TABLE prueba3(ip VARCHAR(30), estado VARCHAR(30))") ||
      //Inserta valores en la tabla
  
      foreach((rango($range)) as $i)
      {
          !$mysqli-&gt;query("INSERT INTO prueba3 (ip, estado) VALUES (". $i .", 'Libre')");
      }
  
      /*!$mysqli-&gt;query("INSERT INTO prueba3(ip, estado) VALUES ('192.168.3.1', 'Libre')")) { */
      //Si falla la creacion de la tabla
      echo "Falló la creación de la tabla: (" . $mysqli-&gt;errno . ") " . $mysqli-&gt;error;
  }
  ?&gt;
  </code></pre>
  
  <p>I need insert each value from that array, and i dont know how.. The problem is the 'foreach' inside the 'if' to insert them..</p>
  
  <p>How can i solve this?</p>