You can't use variable inside strings that way.
For instance you can use :
$cmd="SELECT * FROM mytable WHERE id='$id'";
but you can't use :
$cmd="SELECT * FROM mytable WHERE id='$tab[$id]'";
what you have to do is a concatenation like this :
$cmd="SELECT * FROM mytable WHERE id='".$tab[$id]."'";
So for your code :
mysql_query ("insert into table1 ($red[$i]) values ('$blue[$i]')");
will become :
$cmd = "insert into table1 (".$red[$i])." values ('".$blue[$i]."')"
mysql_query ($cmd);
If it still doesn't work, check the value of the $cmd variable , with a
print $cmd
just before executing the query, to check that you have good values inside your array.