Foros del Web » Programando para Internet » PHP »

Mensaje cuando no existe un registro en la Base Datos

Estas en el tema de Mensaje cuando no existe un registro en la Base Datos en el foro de PHP en Foros del Web. Hola amigos, soy nuevo en el Foro y tengo el siguiente problema: estoy haciendo un sistema de bodega en PHP y Mysql (Base de Datos) ...
  #1 (permalink)  
Antiguo 05/10/2013, 13:29
 
Fecha de Ingreso: octubre-2013
Ubicación: Cauquene
Mensajes: 4
Antigüedad: 10 años, 6 meses
Puntos: 0
Mensaje cuando no existe un registro en la Base Datos

Hola amigos, soy nuevo en el Foro y tengo el siguiente problema: estoy haciendo un sistema de bodega en PHP y Mysql (Base de Datos) y quiero saber como puedo hacer que me aparezca un mensaje o alerta cuando hago una búsqueda de un material ya sea por el código o nombre, la consulta me funciona a la perfección pero cuando ingreso un código que no está registrado quiero que me avise que "el código no se encuentra registrado", no se si se puede hacer sólo con PHP o con Javascript o combinando los dos. La búsqueda la hago mediante un formulario.html que al aceptar me lleva a uno php que se llama EjecutaConsultaMaterialCodigo.php, aquí se los dejo
  #2 (permalink)  
Antiguo 05/10/2013, 13:33
Avatar de AnGuisi  
Fecha de Ingreso: julio-2013
Ubicación: San Felipe - Yaracuy
Mensajes: 122
Antigüedad: 10 años, 9 meses
Puntos: 2
Respuesta: Mensaje cuando no existe un registro en la Base Datos

Si posteas el codigo PHP que hace tu busqueda te podria dar un ejemplo exacto de como puedes hacer amigo.
  #3 (permalink)  
Antiguo 05/10/2013, 13:51
 
Fecha de Ingreso: julio-2013
Mensajes: 309
Antigüedad: 10 años, 9 meses
Puntos: 2
Respuesta: Mensaje cuando no existe un registro en la Base Datos

deberias poner el codigo
  #4 (permalink)  
Antiguo 05/10/2013, 17:33
 
Fecha de Ingreso: octubre-2013
Ubicación: Cauquene
Mensajes: 4
Antigüedad: 10 años, 6 meses
Puntos: 0
Respuesta: Mensaje cuando no existe un registro en la Base Datos

Aquí va el php
<?php
require_once ("conexion.php");
?>

<html>

<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="author" content="Pehuenche (www.pehuenche.cl)" />
<link rel="stylesheet" href="css/main.css" type="text/css" />
<title>Sistema de Bodega Pehuenche</title>
<style type "text/css">
.encabezado{ background-color:blue; color:#FFFACC; font-weight:bold }
.registros {background-color:#FAF9F3}
</style>

<script language="javascript">
alert(' C\u00f3digo no registrado ');
//window.location='FormularioConsultaMaterialCodigo. html';

</script>


</head>

<body>
<div id="header">
<IMG SRC="imagenes/logo.jpg" WIDTH="140">
<div class="wrap">

<h1 id="logo"><a href="#">Sistema de Bodega Pehuenche</a></h1>

<p><br />-----</p>

<ul id="menu">

<li><a class="current" href="index.html">Inicio</a></li>
<li><a href="material.php">Materiales</a></li>
<li><a href="consultar.php">Pr&eacutestamos</a></li>
<li><a href="stock.php">Usuarios</a></li>

</ul>

</div>

<div id="main">
<br>

</div>
<br>
<br>
<br>

<center>
<table width="45%" height="5" border="0" color="blue" >

<td valign="top" align="left" width="300" colspan="500">
<h3><font color="#FC0101">Registro de materiales por c&oacutedigo:</font></h3>


<tr class ="encabezado">

<td valign="top" align="center" width="10">
C&oacutedigo
</td>

<td valign="top" align="center" width="30">
Nombre
</td>

<td valign="top" align="center" width="30">
Descripci&oacute;n
</td>

<td valign="top" align="center" width="11">
Total en stock
</td>

<td valign="top" align="center" width="15">
Medida
</td>

<?php
$sql= "SELECT codigo, nombre, descripcion, total, medida, SUM(cantidad) AS total FROM materiales WHERE codigo= '".$_POST['codigo']."' GROUP BY codigo";
$res= mysql_query($sql, $con);




while($reg=mysql_fetch_array($res))
{
?>

<tr class ="registros">

<td valign="top" align="left" width="10">
<?php
echo ($reg["codigo"]);
?>
</td>

<td valign="top" align="left" width="30">
<?php
echo ($reg["nombre"]);
?>
</td>

<td valign="top" align="left" width="30">
<?php
echo ($reg["descripcion"]);
?>
</td>

<td valign="top" align="center" width="11">
<?php
echo ($reg["total"]);
?>
</td>

<td valign="top" align="center" width="15">
<?php
echo ($reg["medida"]);
?>
</td>

<?php
}
?>

</tr>
</center>
</table>

<center>
<hr color="blue" size=5 width="606">

<br>
<br>
<table>
<tr>
<td>
<a href="material.php" title="Regresar a materiales"><img src="IMAGENES/regresar.jpg" border="0"">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp</a>
</td>

<td>
<button input type="button" name="imprimir" value="Imprimir" title="Imprimir" onClick="window.print();"> <img src="IMAGENES/imprimir.jpg" border="0">
</td>

<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
<a href="FormularioConsultaMaterialCodigo.html" title="Realizar una nueva consulta"><img src="IMAGENES/nuevaConsulta.jpg" border="0""></a>
</td>
</tr>
</table>

</BODY>
</HTML>
  #5 (permalink)  
Antiguo 05/10/2013, 17:44
 
Fecha de Ingreso: octubre-2013
Ubicación: Cauquene
Mensajes: 4
Antigüedad: 10 años, 6 meses
Puntos: 0
Respuesta: Mensaje cuando no existe un registro en la Base Datos

Y este es el formulario html por el cual solicito la consulta:
<html>
<head>

<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="author" content="Pehuenche (www.pehuenche.cl)" />
<link rel="stylesheet" href="css/main.css" type="text/css" />
<title>Sistema de Bodega Pehuenche</title>


<style type "text/css">

.encabezado{ background-color:blue; color:#FFFACC; font-weight:bold }
.registros {background-color:#FAF9F3}
</style>


</head>
<body>

<div id="header">
<IMG SRC="imagenes/logo.jpg" WIDTH="140">
<div class="wrap">

<h1 id="logo"><a href="#">Sistema de Bodega Pehuenche</a></h1>

<p><br />-----</p>

<ul id="menu">


<li><a class="current" href="index.html">Inicio</a></li>
<li><a href="material.php">Materiales</a></li>
<li><a href="consultar.php">Pr&eacutestamos</a></li>
<li><a href="#">Bajas</a></li>
<li><a href="stock.php">Usuarios</a></li>
</ul>

</div>

<div id="main">
<div class="1">

<br>

</div>

<form name="consulta1" method="post" action="EjecutaConsultaMaterialCodigo.php">

<br>
<br>
<h1 span style="color: #1F79EE">Ingrese el c&oacutedigo:</h1></span>
<br>

<TABLE BGCOLOR="#4A5F90" width="34%" height="5" border="5" color="blue" >


<TR>
<TD WIDTH="30"
HEIGHT="47"><font color="FFFFFF" size="4">C&oacutedigo:
<INPUT TYPE="text" NAME="codigo" SIZE="25" MAXLENGTH="40"></TD>
</TR>


<TABLE BGCOLOR="#1F79EE" width="34%" height="5" border="0" color="blue" >

<tr>
<TD WIDTH="40"
HEIGHT="50"><input type="reset" value=" Borrar datos " title="Borrar datos"></td>

<TD WIDTH="40"
HEIGHT="40">&nbsp;<input type="submit" value=" Consultar " title=" Ir a la consulta"align="right"></td>

<TD WIDTH="40"
HEIGHT="40"><a href="Material.php" title="Regresar a materiales"><img src="IMAGENES/regresar2.jpg" border="0" align="right"></a></td>
</tr>

</table>
</form>

</body>
</html>
  #6 (permalink)  
Antiguo 05/10/2013, 18:46
Avatar de xSkArx  
Fecha de Ingreso: marzo-2008
Ubicación: Chile
Mensajes: 945
Antigüedad: 16 años, 2 meses
Puntos: 96
Respuesta: Mensaje cuando no existe un registro en la Base Datos

Lee la documentaciin de la funcion mysql_num_rows() te servira para lo que necesitas
__________________
Busca, lee y practica todo lo que puedas.
Usa siempre el buscador antes de postear.
Si posteas código, utiliza el HIGHLIGHT correcto.

Etiquetas: formulario, html, mensaje, mysql, registro
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:15.