[development] Array

Bob Hutchinson hutchlists at midwales.com
Wed Jun 8 07:27:23 UTC 2011


On Tuesday 07 June 2011, Damian Adriel Perez Valdes wrote:
> Hi:
> 
> I have a select multiple, but i can´t get the values
> 
> for ($i=0; $i < 2; $i++){
>    $query3 = "INSERT INTO {usuarios} ( id_p, id_user ) values (
> '".$last_id."', %d )";
>    $queryResult3 = db_query ( $query3, $usuario[$i] );
> }
> 
> save a empty value.
> 
> thanks

This is a support question, not development so you are on the wrong list but 
here is an answer anyway:

usuarios.id_p should be set to auto increment so you should not try to write 
to it at all, let mysql do it for you.

for ($i=0; $i < 2; $i++){
   $query3 = "INSERT INTO {usuarios} (id_user) VALUES (%d)";
   if (! db_query ( $query3, array($usuario[$i]) ) ) {
    drupal_set_message(t('Error while trying to insert.'), 'error');
  }
}

For D7 use db_insert, see api.drupal.org for details.


-- 
-----------------
Bob Hutchinson
Midwales dot com
-----------------


More information about the development mailing list