Combobox values sometimes doesn't insert into MySQL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Gouveia
Forum Newbie
Posts: 19
Joined: Mon Apr 27, 2009 3:55 pm
Location: Brazil

Combobox values sometimes doesn't insert into MySQL

Post by Gouveia »

Hello people!

I'm having a problem here. I've moved into a project where the previous developer had established 3 files: a HTML, a PHP and two JSs.
-- The HTML defines the layout of the page, with the fields and such.
-- The PHP defines what is going to happen, which function is gonna be activated, etc.
-- The JSs defines some toolbar and the MySQL queries, which are automatically built.

But there's a problem. Sometimes the combobox values work, sometimes they doesn't. And to be even worse, it's not that random. It works for all odd numbers, and doesn't for all even numbers. Here's the important bits of the code:

JS1, MySQL query Part:

Code: Select all

function insertSQL(btnobj)
{ 
   
   // Cria a URL e a ação a ser executada dentro do script
   var sURL   = document.URL.replace("_html", "_php");
   sURL       = sURL.replace(".html",".php");
   sURL       = Left(sURL, document.URL.indexOf("?"));
   sURL       = sURL + "?acao=" + btnobj.title;
 
   var sCOLUNAS = '';
   
   // Configura as colunas que ser?o enviadas ao PHP para compor a SQL (INSERT OU UPDATE)
  
   //alert(document.forms[0].elements[i].value);
 
   for (i = 0; i < document.forms[0].elements.length; i++)
   {
       var verifica = document.forms[0].elements[i].name;
       if (verifica.indexOf('table') == 0)
       {
         sCOLUNAS += "&" + document.forms[0].elements[i].id + "=" + verifica.substring(6,7) + "," + document.forms[0].elements[i].value;
       }
   }   
   
   makePOSTRequest(sURL ,sCOLUNAS);
   //window.open(sURL + sCOLUNAS,"corpo");
 
}
PHP1, Insert Part:

Code: Select all

switch (strtolower($_REQUEST["acao"])) 
   {    
         case "novo":
              
              if (!validacao()) break;
              $comando = "INSERT INTO contas SET ";
        
              $oConexao->sql      = colunasSQL($comando);
           
              $oConexao->executaQuery();
           
              $oConexao->sql      = "SELECT LAST_INSERT_ID() AS id;";
              $rs_colunas = $oConexao->executaQuery();
 
              if (MYSQL_NUM_ROWS($rs_colunas)>0)
              { 
                 $linha = MYSQL_FETCH_ARRAY($rs_colunas, MYSQL_ASSOC);
 
                 // Refresh na página para atualizar o código da entidade
                 $pagina = $_SERVER['PHP_SELF'] . "?acao=procurar&where=cta_id=" . $linha["id"] . "&mensagem=<h3> Registro gravado com sucesso. ID: <strong>" . $linha["id"] . "</strong></h3><br>";
                 echo "<META http-equiv='refresh' content='0;URL=" . $pagina . "'>";
                 exit;
                 
              }
              else
              {
                 echo "Ocorreu um erro na inclusão do registro!";  
              }
             break;
It may be kinda confusing, but it does work for all other fields that we're using (Texts and Checkboxes). I don't know what the problem is, but I'm almost sure that it is within those two parts.

Thanks for any help that you guys may give ;)
Post Reply