Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Boa tarde galera !
Segue meu codigo, e depois minha pergunta =)
$lista_chave = mysql_query("SELECT " . $GLOBALS["chave_primaria"] . " FROM " . $GLOBALS["tabela"] . $_SESSION["clausula"]);
$atual_chave = mysql_fetch_array($lista_chave, MYSQL_ASSOC);
$sql = 'SELECT * FROM '.$GLOBALS['tabela'].' WHERE nome = \''.$_POST["teste"].'\'';
$resultado = mysql_query( $sql )or die( mysql_error() );
$row = mysql_fetch_array($resultado, MYSQL_ASSOC);//MYSQL_ASSOC=retira seus indices numeros.
//atualiza_selecionados faz a strind que é jogada no update (logo depois de SET) para autualizar a table.
$atualiza_selecionados =
"";
$contador = 0;
foreach ($row as $indice => $valor)
{
$atualiza_selecionados .=
($contador == 0 ? "" : ",") . $indice . " = \"" . escapa($_POST[$indice] . $_POST['Codigo_Produto'] . $atual_chave[$GLOBALS["chave_primaria"]]) . "\"";
($contador == 0 ? "" : ",") . $indice . " = \"" . escapa($_POST[$indice] . $_POST['Nome_Produto'] . $atual_chave[$GLOBALS["chave_primaria"]]) . "\"";
($contador == 0 ? "" : ",") . $indice . " = \"" . escapa($_POST[$indice] . $_POST['Titulo'] . $atual_chave[$GLOBALS["chave_primaria"]]) . "\"";
($contador == 0 ? "" : ",") . $indice . " = \"" . escapa($_POST[$indice] . $_POST['Descricao'] . $atual_chave[$GLOBALS["chave_primaria"]]) . "\"";
($contador == 0 ? "" : ",") . $indice . " = \"" . escapa($_POST[$indice] . $_POST['Num_Downloads'] . $atual_chave[$GLOBALS["chave_primaria"]]) . "\"";
//echo $_POST[$indice . "_" . $atual_chave[$GLOBALS["chave_primaria"]]]."<br>";
}
$query = "UPDATE " . $GLOBALS["tabela"] . " SET " . $atualiza_selecionados . " WHERE " . $GLOBALS["chave_primaria"] . " = \"" . escapa($atual_chave[$GLOBALS["chave_primaria"]]) . "\"";
Meus dados n estao sendo atualizados, e sim "acrescentado aos dados antigos" mais nao consigo encontrar meu erro :(
obg a todos =)
>
Boa tarde galera !
Segue meu codigo, e depois minha pergunta =)
$lista_chave = mysql_query("SELECT " . $GLOBALS["chave_primaria"] . " FROM " . $GLOBALS["tabela"] . $_SESSION["clausula"]);
$atual_chave = mysql_fetch_array($lista_chave, MYSQL_ASSOC);
$sql = 'SELECT * FROM '.$GLOBALS['tabela'].' WHERE nome = \''.$_POST["teste"].'\'';
$resultado = mysql_query( $sql )or die( mysql_error() );
$row = mysql_fetch_array($resultado, MYSQL_ASSOC);//MYSQL_ASSOC=retira seus indices numeros.
//atualiza_selecionados faz a strind que é jogada no update (logo depois de SET) para autualizar a table.
$atualiza_selecionados =
"";
$contador = 0;
foreach ($row as $indice => $valor)
{
$atualiza_selecionados .=
($contador == 0 ? "" : ",") . $indice . " = \"" . escapa($_POST[$indice] . $_POST['Codigo_Produto'] . $atual_chave[$GLOBALS["chave_primaria"]]) . "\"";
($contador == 0 ? "" : ",") . $indice . " = \"" . escapa($_POST[$indice] . $_POST['Nome_Produto'] . $atual_chave[$GLOBALS["chave_primaria"]]) . "\"";
($contador == 0 ? "" : ",") . $indice . " = \"" . escapa($_POST[$indice] . $_POST['Titulo'] . $atual_chave[$GLOBALS["chave_primaria"]]) . "\"";
($contador == 0 ? "" : ",") . $indice . " = \"" . escapa($_POST[$indice] . $_POST['Descricao'] . $atual_chave[$GLOBALS["chave_primaria"]]) . "\"";
($contador == 0 ? "" : ",") . $indice . " = \"" . escapa($_POST[$indice] . $_POST['Num_Downloads'] . $atual_chave[$GLOBALS["chave_primaria"]]) . "\"";
//echo $_POST[$indice . "_" . $atual_chave[$GLOBALS["chave_primaria"]]]."<br>";
}
$query = "UPDATE " . $GLOBALS["tabela"] . " SET " . $atualiza_selecionados . " WHERE " . $GLOBALS["chave_primaria"] . " = \"" . escapa($atual_chave[$GLOBALS["chave_primaria"]]) . "\"";
Meus dados n estao sendo atualizados, e sim "acrescentado aos dados antigos" mais nao consigo encontrar meu erro :(
obg a todos =)
ps : descobri que alguma parte do meu codigo esta errada, mas qual ?
Carregando comentários...