alexndrre Posted November 1, 2019 Share Posted November 1, 2019 Hello people! Well, I'm working on a site that has a financing simulator that asks for your data and a value related to cars, real estate and motorcycles. When simulating, it sends you to a page, calculating the closest result and sends your data to the database. However, he has a problem now. When you try to simulate, it no longer shows the result, it even loads the table but has no content, and the simulator form quickly pops up again. Check out an example at http://vitorconsorcios.com.br/simulador.php, below has the source code of the site. I've tried everything, but this is my last solution. What could be the cause of this? <?php include("injection.php"); /* if (isset($_POST['valorcon']) */ $valorcon = (int) tira_virgula_para_ponto( $_POST['valorcon'] ); $plano=anti_injection($_POST["plano"]); $tipo=anti_injection($_POST["tipo"]); $nomecon=anti_injection($_POST["nomecon"]); $telefone=anti_injection($_POST["telefone"]); $emailcon=anti_injection($_POST["emailcon"]); $cidadecon=anti_injection($_POST["cidadecon"]); if ($valorcon>0) { // Inseri a procura $tsql = " insert simulacao set plano='$plano' , tipo = '$tipo' , valor = $valorcon , nome = '$nomecon' , telefone = '$telefone' , email = '$emailcon' , cidade = '$cidadecon' "; //echo $tsql; //exit; $sql_insert = fbd($tsql,"","inserir simulacao"); ?> <div class="col-md-5"> <img src="img/simule.jpg" class="imagem" alt="Vitor Consórcios"> </div> <div class="col-md-7"> <h4>Confira a simualçao abaixo:</h4><br/> <table> <thead> <tr> <th>Descrição</th> <th>Valor do Crédito</th> <th>Valor da Parcela</th> <th>Valor da Meia Parcela</th> <th>Duração</th> </tr> </thead> <tbody> <?php $_SESSION['splano'] = $plano; $_SESSION['svalorcon'] = $valorcon; $_SESSION['stipo'] = $tipo ; if ($plano=='Crédito') { $tsql = " (SELECT * FROM `consulta` where tipo='$tipo' and credito>=$valorcon order by credito limit 2 ) UNION (SELECT * FROM `consulta` where tipo='$tipo' and credito<$valorcon order by credito desc limit 2 ) order by credito "; } ELSE { $tsql = " (SELECT * FROM `consulta` where tipo='$tipo' and parcela>=$valorcon order by parcela limit 2 ) UNION (SELECT * FROM `consulta` where tipo='$tipo' and parcela<$valorcon order by parcela desc limit 2 ) order by parcela "; } $_SESSION['sqlExecutar'] = $tsql ; //echo $tsql; //exit; $sql = fbd($tsql,"","Seleciona as empresa"); $num_rows = mysql_num_rows($sql); if ($num_rows>0) { ?> <script language= "JavaScript"> location.href="resultado.php" </script> <?php } ?> <script language= "JavaScript"> location.href="simulador.php" </script> <?php while($dados= mysql_fetch_array($sql)){ ?> <tr> <td align="left"><? echo $dados[descricao]; ?></td> <td>R$ <? echo valor_ponto_virgula( $dados["credito"] ); ?></td> <td>R$ <? echo valor_ponto_virgula( $dados["parcela"] ); ?></td> <td>R$ <? echo valor_ponto_virgula( $dados["parcela"]/2 ); ?></td> <td><? echo $dados["duracao"] ; ?></td> <?php } ?> </tbody> </table> </div> </div> <p> </p> <p> </p> </div> <?php } ELSE { ?> <h2>SIMULE AGORA SEU CONSÓRCIO!</h2><br/><br/> <div class="col-md-6"> <img src="img/simule.jpg" class="imagem" alt="Vitor Consórcios"> </div> <div class="col-md-1"></div> <form action="simulador.php" method="post" name="dados" id="dados" onSubmit="return validaform()"> <div class="col-md-5 esquerda"> Selecione o bem<br/> <select name="tipo" type="text" class="contat3" placeholder="Selecione o bem"> <option value="Imóvel"" style="background-color: #fff;">Imóveis</option> <option value="Automóvel"" style="background-color: #fff;">Automóveis</option> <option value="Moto" style="background-color: #fff;">Motos</option> </select><br/> Selecione o plano<br/> <select name="plano" type="text" class="contat3"> <option value="Crédito"" style="background-color: #fff;">Crédito</option> <option value="Parcela"" style="background-color: #fff;">Parcela</option> </select><br/> <input name="valorcon" type="text" id="valorcon" class="contat3" placeholder="Digite o valor" maxlength="1000" /><br/> <input name="nomecon" type="text" id="nomecon" class="contat3" placeholder="Nome" maxlength="1000" /><br/> <input name="telefone" type="text" onkeypress="Mascara('TEL',this,event);" type="text" id="telefone" class="contat3" placeholder="Telefone" /> <!--- <input name="tel2" type="text" id="tel2" onkeypress="Mascara('TEL',this,event);" /><br/> ---> <input name="emailcon" type="text" id="emailcon" class="contat3" placeholder="E-mal" maxlength="1000" /><br/> <input name="cidadecon" type="text" id="cidadecon" class="contat3" placeholder="Cidade" maxlength="1000" /> <br/><br/><br/> <a id="enviar-form" class="button solid-color" href="#">Enviar</a> <input type="submit" id="enviar-form-btn" style="display: none;" /> </div> </form> </div> <p> </p> <p> </p> </div> <?php } // 14-05-2018 ?> </div> </div> Quote Link to comment https://forums.phpfreaks.com/topic/309447-simulator-made-in-php-does-not-appear-calculation-result/ Share on other sites More sharing options...
ginerjm Posted November 1, 2019 Share Posted November 1, 2019 Not trying to be difficult here but I want to ask - What has changed in your code? Working scripts that suddenly don't work usually means you changed something. Have you tried adding any kind of debugging code (echo's or writes to a text file) to track the actions that your script is taking? Quote Link to comment https://forums.phpfreaks.com/topic/309447-simulator-made-in-php-does-not-appear-calculation-result/#findComment-1571160 Share on other sites More sharing options...
Barand Posted November 1, 2019 Share Posted November 1, 2019 3 minutes ago, ginerjm said: What has changed in your code? … or in your environment? For example, an upgrade to PHP 7.0+ would cause your script to crumble (mysql_ functions obsolete) 38 minutes ago, alexndrre said: while($dados= mysql_fetch_array($sql)) Quote Link to comment https://forums.phpfreaks.com/topic/309447-simulator-made-in-php-does-not-appear-calculation-result/#findComment-1571161 Share on other sites More sharing options...
alexndrre Posted November 1, 2019 Author Share Posted November 1, 2019 Just now, Barand said: … or in your environment? For example, an upgrade to PHP 7.0+ would cause your script to crumble (mysql_ functions obsolete) Just now, ginerjm said: Not trying to be difficult here but I want to ask - What has changed in your code? Working scripts that suddenly don't work usually means you changed something. Have you tried adding any kind of debugging code (echo's or writes to a text file) to track the actions that your script is taking? No updates or changes have been made. I had not moved this part, just made a backup and it was like this. Quote Link to comment https://forums.phpfreaks.com/topic/309447-simulator-made-in-php-does-not-appear-calculation-result/#findComment-1571163 Share on other sites More sharing options...
gw1500se Posted November 1, 2019 Share Posted November 1, 2019 Personally I would abandon trying to fix the code and instead rewrite it using PDO. Since it uses deprecated code that is going away in any case, it makes no sense to waste time trying to fix it. 1 Quote Link to comment https://forums.phpfreaks.com/topic/309447-simulator-made-in-php-does-not-appear-calculation-result/#findComment-1571164 Share on other sites More sharing options...
ginerjm Posted November 1, 2019 Share Posted November 1, 2019 And I would learn how to structure your scripts to separate the logic (PHP) from the presentation (HTML/JS) so that it is easier to read/understand and maintain. As it is your script is very hard to follow. A good style would be to place your php at the beginning and your html at the end and your js embedded inside of that HTML. Test the current status of the script's execution (is this the first time in here? or not?) to determine what you php code should do and avoid trying to handle things from the form that don't yet exist. A nice clean method of writing php scripts would leave you with just one pair of php tags (<?php & ?>) in it. Quote Link to comment https://forums.phpfreaks.com/topic/309447-simulator-made-in-php-does-not-appear-calculation-result/#findComment-1571168 Share on other sites More sharing options...
ginerjm Posted November 1, 2019 Share Posted November 1, 2019 But - getting back to your original question. If the script used to work and now it doesn't something has changed. If not the code then, as Barand said, it must be your environment. PHP Version? Default folders in use? .INI settings? I mean - what has changed? We know something has, you just have to find it. Basically - what is the difference between the time when it did work and now? Do you have php error checking turned on in your ini? Have you checked the error log file? Quote Link to comment https://forums.phpfreaks.com/topic/309447-simulator-made-in-php-does-not-appear-calculation-result/#findComment-1571171 Share on other sites More sharing options...
alexndrre Posted November 6, 2019 Author Share Posted November 6, 2019 That was fixed. Because of the language signals, the database was under one name and php another. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/309447-simulator-made-in-php-does-not-appear-calculation-result/#findComment-1571273 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.