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=" ".$_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?