Problemas con javascript
Hola jorvidu,
a lo mejor no me puedes ayudar pero como hay código php a lo mejor tengo un fallo o algo.
Te comento, hago una consulta según tres campos. Si la consulta la hago con dni o usuario todo va bien, pero si la hago por nombre y apellido no me ejecuta el código javascript.
La consulta la hace correctamente pero no entiendo porque falla en javascript.
No lo entiendo porque ese código lo ejecuta indiferentemente como hagas la búsqueda.
Te pongo el código:
<?php
session_start();
if (isset($_SESSION['usuario']))
{
include("../conectar.php");
$dni = $_REQUEST['dni'];
$user = $_REQUEST['user'];
$nom = $_REQUEST['nom'];
$ape = $_REQUEST['ape'];
$tipo = $_REQUEST['tipo'];
$db = conectar();
if ($dni != "")
$seleccion="select dni,nombre,apellidos,usuario from registrado where dni='".$dni."' and estado='Alta' and tipo='".$tipo."'";
else
{
if ($user != "")
$seleccion="select dni,nombre,apellidos,usuario from registrado where usuario='".$user."' and estado='Alta' and tipo='".$tipo."'";
else
$seleccion="select dni,nombre,apellidos,usuario from registrado where nombre='".$nom."' and apellidos='".$ape."' and estado='Alta' and tipo='".$tipo."'";
}
$rs=consulta($db,$seleccion);
if($rs->RecordCount()!=0 && $rs->RecordCount()!= -1)
{
?>
<script type="text/javascript">
document.getElementById('dni').value= "<?php echo $rs->fields[0];?>";
document.getElementById('nombre').value= "<?php echo $rs->fields[1];?>";
document.getElementById('ape').value= "<?php echo $rs->fields[2];?>";
document.getElementById('user').value= "<?php echo $rs->fields[3];?>";
document.getElementById('b_baja').disabled = false;
document.getElementById('dni').setAttribute("readOnly","readOnly") ;
document.getElementById('nombre').setAttribute("readOnly","readOnly") ;
document.getElementById('ape').setAttribute("readOnly","readOnly") ;
document.getElementById('user').setAttribute("readOnly","readOnly") ;
</script>
<?php
}
else
{
?>
<script type="text/javascript">
alert("El usuario no existe o esta dado de baja");
// document.location.href="http://localhost/director.php";
</script>
<?php
}
close($rs);
close($db);
}
?>
Lo que esta en negrita es la parte que no hace cuando la búsqueda es por nombre. La consulta la hace bien, lo he comprobado.
a lo mejor no me puedes ayudar pero como hay código php a lo mejor tengo un fallo o algo.
Te comento, hago una consulta según tres campos. Si la consulta la hago con dni o usuario todo va bien, pero si la hago por nombre y apellido no me ejecuta el código javascript.
La consulta la hace correctamente pero no entiendo porque falla en javascript.
No lo entiendo porque ese código lo ejecuta indiferentemente como hagas la búsqueda.
Te pongo el código:
<?php
session_start();
if (isset($_SESSION['usuario']))
{
include("../conectar.php");
$dni = $_REQUEST['dni'];
$user = $_REQUEST['user'];
$nom = $_REQUEST['nom'];
$ape = $_REQUEST['ape'];
$tipo = $_REQUEST['tipo'];
$db = conectar();
if ($dni != "")
$seleccion="select dni,nombre,apellidos,usuario from registrado where dni='".$dni."' and estado='Alta' and tipo='".$tipo."'";
else
{
if ($user != "")
$seleccion="select dni,nombre,apellidos,usuario from registrado where usuario='".$user."' and estado='Alta' and tipo='".$tipo."'";
else
$seleccion="select dni,nombre,apellidos,usuario from registrado where nombre='".$nom."' and apellidos='".$ape."' and estado='Alta' and tipo='".$tipo."'";
}
$rs=consulta($db,$seleccion);
if($rs->RecordCount()!=0 && $rs->RecordCount()!= -1)
{
?>
<script type="text/javascript">
document.getElementById('dni').value= "<?php echo $rs->fields[0];?>";
document.getElementById('nombre').value= "<?php echo $rs->fields[1];?>";
document.getElementById('ape').value= "<?php echo $rs->fields[2];?>";
document.getElementById('user').value= "<?php echo $rs->fields[3];?>";
document.getElementById('b_baja').disabled = false;
document.getElementById('dni').setAttribute("readOnly","readOnly") ;
document.getElementById('nombre').setAttribute("readOnly","readOnly") ;
document.getElementById('ape').setAttribute("readOnly","readOnly") ;
document.getElementById('user').setAttribute("readOnly","readOnly") ;
</script>
<?php
}
else
{
?>
<script type="text/javascript">
alert("El usuario no existe o esta dado de baja");
// document.location.href="http://localhost/director.php";
</script>
<?php
}
close($rs);
close($db);
}
?>
Lo que esta en negrita es la parte que no hace cuando la búsqueda es por nombre. La consulta la hace bien, lo he comprobado.
1 Respuesta
Respuesta de Jorge Vila
1