Jump to content

Inserir um array na base de dados


Umbus
 Share

Recommended Posts

Boas,

Fiz assim,  mas nao funciona, o que estou a fazer de mal?

while ($row = mysql_fetch_assoc($result)) {

$sala[$x] = $_POST[$row['siteform']];
$x++;
$final1[$x] = $row['siteform'];
}
$sala2 = $sala[$x];
$final = $final1[$x];
for($i=1;$i<count($final);$i++)
{


      $sql = "INSERT INTO salasnicks (";
      for ($i=0; $i<count($final); $i++) {
     $sql .= key($info);
     if ($i < (count($final)-1)) {
        $sql .= ", ";
     } else $sql .= ") ";
        next($final);
     }
     reset($final);
     $sql .= "VALUES (";
     for ($j=0; $j<count($sala2); $j++) {
        $sql .= "'".current($sala2)."'";
        if ($j < (count($sala2)-1)) {
           $sql .= ", ";
        } else $sql .= ") ";
        next($sala2);
     }
         //execute the query
     mysql_query($sql) or die("query failed ".mysql_error());
         return mysql_insert_id();
      }

APARTE: Usa o Geshi, para o post ficar mais legível.

Eu sou eu e eu sou aquele que sou eu...

Link to comment
Share on other sites

Isso tem de dar um erro qualquer,  esse die("query failed ".mysql_error()); devolve algo?

É que sem saber qual é o erro não dá para resolver o problema...

Podes fazer uma coisa mais simples, que é mostrar a string que estás a enviar para o MySQL e corrê-la directamento no MySQL de forma a ver se há algum problema ai.

10 REM Generation 48K!
20 INPUT "URL:", A$
30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50
40 PRINT "404 Not Found"
50 PRINT "./M6 @ Portugal a Programar."

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.