0

I have 2 problems with the next code, i have 2 pages on PHP, the first page call the second through ajax. first problem is with the form, i would like to show the options according the user privileges. the normal HTML code works fine, but the "echo" code no.

the second problem its about the buttons, i have styles for 2 buttons; btn-enviar and avan. the "btn-enviar" button works fine, but the "avan"button not.

thanks for all.

PHP code segtick.php

<DOCTYPE HTML>
<html>
 <?php
  session_start();
  
  
  $nose=$_SESSION['userid'];
  $nombre="&nbsp; &nbsp;".$_SESSION['nombre'];
  $estado= $_SESSION['estado'];
  $permiso=$_SESSION['permiso'];
  
 ?>

<style>
 table, td, th {
    border: 1px solid purple;
 style="width:100%"
}

th {
    background-color: purple;
    color: white;
}

#btn-enviar { width: 100px;
  height: 40px;
  border-radius: 10px;
  font-size:120%;

#avan { width: 100px;
  height: 40px;
  border-radius: 10px;
  font-size:120%;
  }

  
.campos {
 background-color: #E9E9E9;
 border: 2px solid #A8A8A8;
 font-family: Verdana;
 font-size: 10px;
}  

  
</style> 
 
<head>
 <BODY BGCOLOR=#e7e5e4>
 <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<title>Segtick</title>
<script>
 $(function(){
  
  $("#btn-enviar").click(function(){
   var url="dame-segtick.php";
   $.ajax({
    type:"POST",
    url:url,
    data:$("#formulario").serialize(),
    success:function(data)
    {
     $("#resultado").html(data);
     
     }
    });
    return false
   });
  });
  
  $(function(){
  
  $("#avan").click(function(){
   var url="guar-segtick.php";
   $.ajax({
    type:"POST",
    url:url,
    data:$("#formulario").serialize(),
    success:function(data)
    {
     $("#resultado").html(data);
     
     }
    });
    return false
   });
  });
</script>

</head>

<body>
 
<?php
 require("../abrir.php");
 mysql_set_charset('utf8');




?>

<br>

<form metho="post" id="formulario">
<?php

 echo '
<table width="100%" border="0" cellpadding="5">
 <tr>
 <td width="60%">';
 
 ?>
 <b>ID:</b>
 <br>
 <input align="center" type="text" name="id" value="">
 <br>
 <b>Avance:</b>
 <textarea style="resize:none; height:130px !important; width:100% !important" align="center" type="text" name="avan"></textarea>
 
<?php
 
 echo '
 </td>
 <td width="40%">
 ';
 if ($permiso==3){
 echo '
 <p>Prioridad:</p>
 
   <input type="radio" name="prio" value="Baja">Baja
   <input type="radio" name="prio" value="Media">Media
   <input type="radio" name="prio" value="Alta">Alta
 
 <p>Impacto:</p>
 
 <input type="radio" name="impa" value="Cero">Cero
   <input type="radio" name="impa" value="Bajo">Bajo
   <input type="radio" name="impa" value="Medio">Medio
   <input type="radio" name="impa" value="Alto">Alto
 ';}
 echo '
 <p>Estatus:</p>
 
 <input type="radio" name="esta" value="Inicio">Inicio
   <input type="radio" name="esta" value="Escalado">Escalado
   <input type="radio" name="esta" value="Seguimiento">Seguimiento
   <input type="radio" name="esta" value="Cerrado">Cerrado</td>
   </tr>
 ';

?>
</table>

  
</form>
<P ALIGN=center>
<input  type="button" id="btn-enviar" value="Check" >
<input  type="button" id="avan" value="Guardar" >
</p>

 <div id="resultado"></div>
 
</body>
</html>

the second page is guar segtick.php

<?php
session_start();
  $nose=$_SESSION['userid'];
  $nombre=$_SESSION['nombre'];
  $estado= $_SESSION['estado'];
  $permiso=$_SESSION['permiso'];

require("../abrir.php");
 mysql_set_charset('utf8');
 
 $fecha=date("Y-m-d")."T".date("H:i:s");
 $resultado="";
  
 $id=$_POST["id"];
 $avan="";
 @$avan=$_POST["avan"];
 $prio=$_POST["prio"];
 $impa=$_POST["impa"];
 $esta=$_POST["esta"];
 
 $sql="select * from tickets where idtickets=$id";
 $result = mysql_query($sql);
 
 while($row = mysql_fetch_array($result)) {  
 $estadb=$row['esta'];
 }
 echo "<script>alert('Estado en la DB $estadb.";
  
  if ($avan !=""){
  
  mysql_query("UPDATE `iprancolbd`.`tickets` 
     SET `comen`=concat(`comen`,'//$fecha/$nombre/$avan') where idtickets=$id;");
      } 
  
  if ($prio !=""){
  
  mysql_query("UPDATE `iprancolbd`.`tickets` 
     SET `prio`=$prio where idtickets=$id;");
      } 
  
  if ($impa !=""){
   
  mysql_query("UPDATE `iprancolbd`.`tickets` 
     SET `impa`=$impa where idtickets=$id;");
      } 
      
  if ($esta !=""){
   if ($row['esta']!="Cerrado")
    mysql_query("UPDATE `iprancolbd`.`tickets` 
     SET `esta`=$esta where idtickets=$id;");
      } 
    else {echo "<script>alert('Este ticket se encuentra cerrado."; }
    
  echo "<script>alert('Adelanto guardado, use el boton check para verificar');</script>"; 

?>

EDIT: thanks for help. I understand in the answers than the PHP headers only be sent before any output, but I'm not sure because the php show the code according to the account privileges using the "if".

In addition I would like to known whats the problem with the "avan" button. why not apply the style?

fgalan
  • 11,732
  • 9
  • 46
  • 89
  • Consult these following links http://php.net/manual/en/function.mysql-error.php and http://php.net/manual/en/function.error-reporting.php and apply that to your code. Check your console also. – Funk Forty Niner Dec 09 '15 at 20:27
  • this is incorrect `` that should read as ` ` – Funk Forty Niner Dec 09 '15 at 20:28
  • Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Dec 09 '15 at 20:32
  • [Your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – Jay Blanchard Dec 09 '15 at 20:33
  • Try putting both event handlers within same $(function(){} construct – Casey ScriptFu Pharr Dec 09 '15 at 20:33
  • @Jay - and ys, jay is correct – Casey ScriptFu Pharr Dec 09 '15 at 20:33
  • thanks people, i decided take another way, show all the form and limit the actiosn in the background php page. – Rafael Valbuena Dec 11 '15 at 16:53
  • hello I solved the "avan" button problem. I missed a "}" to close the style. :o – Rafael Valbuena Dec 11 '15 at 20:33

0 Answers0