Page 1 of 1

Popup values showing up, but they get blanked out

Posted: Thu Nov 19, 2009 11:55 am
by Gouveia
So guys, this is my problem. I'm trying to make a registration page for my company so they can manage the costumers more effectively. I already have a database crowded with costumers, and I need to query that database so I don't need to type all of the data again. I made a button that opens another PHP file on a pop up and then, through a Javascript, it brings everything that I need back to the parent page, but the only thing that I would really need would be the ID. Ok, no problems. But, when I type everything and submit the data, the only thing that isn't inserted is that ID, everything else is inserted correctly.

Could that be some problem on the Javascript? Or the form?

Re: Popup values showing up, but they get blanked out

Posted: Thu Nov 19, 2009 12:03 pm
by socalocmatt
Post your code please.

Re: Popup values showing up, but they get blanked out

Posted: Thu Nov 19, 2009 12:24 pm
by Gouveia
Thanks, here's the code. Be advised, this is not the prettiest thing you'll ever see, I still need to learn A LOT about PHP.

incluir.php (include.php)

Code: Select all

<HTML>
 
<HEAD>
 
<TITLE>Cadastro de Contato</TITLE>
<link rel="stylesheet" type="text/css" href="../_css/style_menu.css" />
<script type="text/javascript" src="../_javascript/busca.js"></script>
</HEAD>
 
<BODY>
 
<?php
    include 'conecta.php';
    include 'funcoes.php';
?>
 
<div align=center>
 
<br><br>
 
Preencha os campos para efetuar o cadastro do contato:<br><br>
 
<FORM NAME ="formulario" METHOD ="POST" ACTION = "incluir.php">
 
<table>
 
<tr><td align=right>Nome Fantasia:</td><td><INPUT NAME='idCliente' TYPE='TEXT' VALUE='' SIZE='5' MAXLENGTH='5' disabled="disabled"><INPUT ID='CLIFANTAS' NAME='CLIFANTAS' TYPE='TEXT' VALUE='' SIZE='45' MAXLENGTH='45'><INPUT TYPE='IMAGE' SRC='../_images/lupa.png' WIDTH=24 HEIGHT=24 ONCLICK="javascript&#058;busca('idCliente', 'CLIFANTAS')"></INPUT></td></tr>
<tr><td align=right>Razão social:</td><td><INPUT TYPE='TEXT' VALUE='' NAME='CLIRAZSOC' size='60' maxlength='60' disabled="disabled"></td></tr>
<tr><td align=right>Telefone:</td><td><INPUT TYPE='TEXT' VALUE='' NAME='CliTelef1' size='20' maxlength='20' disabled="disabled"></td></tr>
<tr><td align=right>Vendedor:</td><td><INPUT TYPE='TEXT' VALUE='' NAME='venNome' size='20' maxlength='20' disabled="disabled"></INPUT></td></tr>
<tr><td align=right>Customer Number:</td><td><INPUT TYPE='TEXT' VALUE='' NAME='customerNumber' size='8' maxlength='8'></td></tr>
<tr><td align=right>Número Total de Licenças:</td><td><INPUT TYPE='TEXT' VALUE='' NAME='numLicencas' size='5' maxlength='5'></td></tr>
<tr><td align=right>Validade:</td><td><INPUT TYPE='TEXT' VALUE='' NAME='validade' size='1' maxlength='1'> anos</td></tr>
<tr><td align=right>Descrição das Licenças:</td><td><TEXTAREA NAME='descLicencas' cols='40' rows='5'></textarea> </td></tr>
<tr><td align=right>Data de Compra:</td><td><INPUT TYPE='TEXT' VALUE='' NAME='dataCompra' size='10' maxlength='10'></td></tr>
 
<tr><td align=center colspan=2><br><br>
 
<INPUT TYPE = "Submit" Name = "btnGo" VALUE = "Inserir" class = "btn">
 
<br><br>
 
* campos obrigatórios</td></tr></table>
 
</FORM>
 
</div>
 
<?php
 
        $idCliente      =   $_POST['idCliente'];
        $customerNumber =   $_POST['customerNumber'];
        $numLicencas    =   $_POST['numLicencas'];
        $validade       =   $_POST['validade'];
        $descLicencas   =   $_POST['descLicencas'];
        $dataCompra     =   $_POST['dataCompra'];
 
    if ((isset($_POST['btnGo']))){
 
        if (($idCliente == "") || ($customerNumber == "") || ($numLicencas == "") || ($validade == "") || ($descLicencas == "") || ($dataCompra == "")){
            echo "<div class=\"box red\">
                    Aviso
                    <br><br>
                    Você deixou algum campo em branco. Verifique os dados e tente novamente
                    </div>";
        }
        elseif (($validade < 1) || ($validade > 3)){
            echo "<div class=\"box red\">
                    Aviso
                    <br><br>
                    A validade declarada não é válida. Favor colocar um valor entre 1 ano e 3 anos.
                    </div>";    
        }
        else{
            $data = mysqlDate($dataCompra);
            $ins = mysql_query("INSERT INTO licencas SET idCliente = '$idCliente', numLicencas = '$numLicencas', descLicencas = '$descLicencas', validade = '$validade', dataCompra = '$data', customerNumber = '$customerNumber'")
                or die(mysql_error());
 
            echo "<div class=\"box green\">
                    Aviso
                    <br><br>
                    Inserção dos dados feita com sucesso!
                    </div>";
        }
    }
    else{
 
    }
 
?>
 
</BODY>
 
</HTML>
busca.js (search.js)

Code: Select all

function busca(ID, Descricao){ 
 
    var sURL = '../_php/busca.php?filtro=' +  document.getElementById(Descricao).value;
 
    var width  = 650;
 
    var height = 200;
 
    var left   = (screen.width  - width)/2;
 
    var top    = (screen.height - height)/2;
 
    var params = 'width='+width+', height='+height;
    params += ', top='+top+', left='+left;
    params += ', directories=no';
    params += ', location=no';
    params += ', menubar=no';
    params += ', resizable=no';
    params += ', scrollbars=yes';
    params += ', status=no';
    params += ', toolbar=no';
 
    abre_popup=window.open(sURL,'BUSCA', params);
 
    if (window.focus){
        abre_popup.focus();
    }
 
}
 
function busca_devolve(idCliente, CLIFANTAS, CLIRAZSOC, CliTelef1, venNome) {
 
    self.opener.document.formulario.elements['idCliente'].value = idCliente; 
    self.opener.document.formulario.elements['CLIFANTAS'].value = CLIFANTAS;
    self.opener.document.formulario.elements['CLIRAZSOC'].value = CLIRAZSOC;
    self.opener.document.formulario.elements['CliTelef1'].value = CliTelef1;
    self.opener.document.formulario.elements['venNome'].value = venNome;
    self.close();
 
}
busca.php (search.php)

Code: Select all

<HTML>
<HEAD>
 
<TITLE>Consulta de Clientes</TITLE>
<link rel="stylesheet" type="text/css" href="../_css/style_menu.css" />
<script type="text/javascript" src="../_javascript/busca.js"></script>
</HEAD>
<BODY>
<?php
    include 'conecta.php';
    include 'funcoes.php';
    
    $filtro = $_GET['filtro'];
    
    $data = mysql_query("SELECT * FROM hti_001.clientes JOIN hti_001.vendedores ON clientes.clivended = vendedores.venCodigo WHERE clientes.CLIFANTAS like '%$filtro%'")
        or die(mysql_error()); 
    
    $linhas_db = mysql_num_rows($data);
    $linhas = 0;
    
    echo "<div align=center>
        <table border = 2><tr>
        <th>ID</th>
        <th>Nome Fantasia</th>
        <th>Razão Social</th>
        <th>Vendedor</th>
        <th>Telefone</th>
        </tr>";
        
    while ($linhas_db > $linhas) {
 
        $info = mysql_fetch_array($data);
        echo "<tr><td>";
        echo "<a href='javascript&#058;busca_devolve(\"" . $info['clicodigo'] ."\",\"". $info['CLIFANTAS'] . "\",\"" . $info['CLIRAZSOC'] . "\",\"" . $info['CliTelef1'] . "\",\"" . $info['venNome'] . "\")'>";
        echo $info['clicodigo'];
        echo "</td><td>";
        echo $info['CLIFANTAS'];
        echo "</td><td>";
        echo $info['CLIRAZSOC'];
        echo "</td><td>";
        echo $info['venNome'];
        echo "</td><td>";
        echo $info['CliTelef1'];
        echo "</td></tr>";
    
        $linhas++;
 
    }
 
    echo "</table></div>";
 
?>
</BODY>
</HTML>
Thanks for anything that you may help me with.

Posted: Thu Nov 19, 2009 1:25 pm
by Jonah Bron
Lines 32-44 in the last file are the bits of code in question. We need to know what each of those column names mean, and you might want to check for typos. It could be that you simply made a typing error for the ID column.

Re: Popup values showing up, but they get blanked out

Posted: Thu Nov 19, 2009 1:39 pm
by Gouveia
Those lines just bring the data that needs to be displayed to the parent page, and the parent page shows those data correctly, so I don't think that the problem is there...

Gonna try to test it on another server, will post the results.

Re: Popup values showing up, but they get blanked out

Posted: Thu Nov 19, 2009 2:17 pm
by Gouveia
Same thing, every possible field is completed, but only the idCliente field, which comes from the javascript, is missing...

Also, whenever I open that popup, it refreshes my page, even though I never told it to do so. Can that be a problem?