Ir al contenido


Foto

Mensaje cuando un registro no existe en la BD


  • Por favor identifícate para responder
2 respuestas en este tema

#1 victormuñoz

victormuñoz

    Newbie

  • Miembros
  • Pip
  • 9 mensajes

Escrito 04 octubre 2013 - 07:23

Hola, estoy haciendo un sistema de bodega de materiales (Base de datos) con PHP y Mysql, en la cual realizo diferentes consultas, pero me gustaría saber como hago lo siguiente:
                  Por ejemplo, al consultar un meterial por el código, quiero que aparezca un mensaje cuando ingrese un código que no está registrado, el cual diga "código no registrado" o algo así.  Como lo puedo hacer, si se realiza en PHP o JavaScript. Atte. gracias.

Este es archivo.php donde ejecuto la consulta a través de un formulario.html:
<?php
require_once ("conexion.php");
?>

<html>

<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="author" content="Pehuenche ([url=http://www.pehuenche.cl]www.pehuenche.cl[/url])" />
<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="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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&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>

  • 0

#2 jooz

jooz

    Member

  • Miembros
  • PipPip
  • 45 mensajes

Escrito 07 octubre 2013 - 08:01

hola.... benas noches... no soy experto pero espro ayudar, no se si sepas usar ajax, yo por lo general siempre hago un div donde van los mensajes de alertas o notificaciones.... pero por si no lo sabes hacer creo para mi esta es una forma facil de hacer lo que quieres....

<?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);
$count=mysql_num_rows($res);
if ($count!=0)
{

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
}//cierre del while

}//cierre del if

else
{
echo "registro no encontrado";
}
?>



espero sea lo que quieres y que  te funcione....
  • 0

#3 victormuñoz

victormuñoz

    Newbie

  • Miembros
  • Pip
  • 9 mensajes

Escrito 07 octubre 2013 - 08:52

Gracias amigo Jooz, es lo que necesitaba, me funcionó a la perfección
  • 0




IP.Board spam blocked by CleanTalk.