Foros del Web » Programando para Internet » PHP »

Como verificar si un dato fue ingresado a la bd?

Estas en el tema de Como verificar si un dato fue ingresado a la bd? en el foro de PHP en Foros del Web. Buenas tardes, tengo este codigo y quiero saber que debo hacer para que valide si inserta los datos o no. e imprima el mensaje que ...
  #1 (permalink)  
Antiguo 01/09/2010, 15:44
 
Fecha de Ingreso: agosto-2010
Mensajes: 34
Antigüedad: 13 años, 8 meses
Puntos: 0
Pregunta Como verificar si un dato fue ingresado a la bd?

Buenas tardes, tengo este codigo y quiero saber que debo hacer para que valide si inserta los datos o no. e imprima el mensaje que esta en rojo y si no inserta que salga uno parecido donde diga que no fue ingresado y que intente de nuevo

<?php
if($enviar)
{
$con = mysql_connect("localhost","root","root");
mysql_select_db("laboratorio",$con);
$sql= "INSERT INTO lamsofci (id_softw,id_versi,id_casas,tp_seria,tp_siope,nu_c ds,de_softw,de_versi) VALUES ('$id_softw','$id_versi','$id_casas','$tp_seria',' $tp_siope','$nu_cds','$de_softw','$de_versi')";
$result = mysql_query($sql);


echo "<script type=\"text/javascript\">alert(\"Dantos Ingresados\");</script>";


?>
<center>
<h3><font color=Black><a href='software.php'>Aceptar</a></font></h3>
</center>
<?php

}
else
{
?>
<form name='menu' method='post' action='software.php'>
<table height="440"><tr><td></td>
<td></td>
<td></td>
<fieldset>
<td><fieldset><legend><font color=Blue ><H6>INGRESO DE SOFTWARE</font></legend><BR>

<fieldset><table width="158">
<tr><td width="1"></td><td width="83"><font color=Black><h6>CODIGO DE SOFTWARE:</font></td>
<td width="58"><input type='Text' name='id_softw' size='6' maxlength='6'></td>
</tr>
</table></fieldset><br>
<fieldset><table width="589">
<tr>

<td width="114"><font color=Black><h6>CODIGO DE VERSION:</td>
<td width="89"><input type='Text' name='id_versi' size='6' maxlength='6'></font></td>

<td width="111"><font color=Black><h6> CASA DE SOFTWARE:</td>
<td width="83"><select name='id_casas' id='id_casas' >
<option value= 'N/A' >.....</option>

<?php
$con = mysql_connect("localhost","root","root");
mysql_select_db("laboratorio",$con);

$sql="select id_casas, de_casas from lamcassf";
$respuesta= Mysql_query ($sql, $con);
while ($row= Mysql_fetch_array ($respuesta))
echo "<option value='".$row["id_casas"]."'>" . $row["de_casas"]. "</option>\n";

echo "</select>";
?>


</select></td></tr>
</table></fieldset><br>
<fieldset><table>
<tr>
<td width="210" height="49"><font color=Red><h6>MANEJA SERIAL DE ACTIVACION?:</font></td>
<td width="150"><select name='tp_seria' id='tp_seria' >
<option value= 'S/N' >.....</option>
<option value= 'S' >SI</option>
<option value= 'N' >NO</option></select></td>

<td width="111"><font color=Red><h6>ES SISTEMA OPERATIVO?:</font></td>
<td width="281"><select name='tp_siope' id='tp_siope' >
<option value= 'S/N' >.....</option>
<option value= 'S' >SI</option>
<option value= 'N' >NO</option></select></td></tr>
</table></fieldset><br>
<fieldset><table>
<tr>
<td width="100"><font color=Black><h6>CANTIDAD DE CDS:</font></td>
<td width="36" ><input type='Text' name='nu_cds' size='6' maxlength='6'></td>
</tr>
</table></fieldset><br>

<fieldset><table>
<tr><td width="90"><font color=Black><h6>DESCRIPCION DEL SOFTWARE:</font></td>
<td width="80"><input type=hidden name=subject value="opinión">
<P><TEXTAREA id=TEXTAREA1 style="WIDTH: 150px; HEIGHT: 70px" name="de_softw" rows=10 cols=36>
</TEXTAREA></td><TD width="50"></TD>
<td width="90"><font color=Black><h6>DESCRIPCION DE VERSION:</font></td>
<td width="80"><input type=hidden name=subject value="opinión">
<P><TEXTAREA id=TEXTAREA1 style="WIDTH: 150px; HEIGHT: 70px" name="de_versi" rows=10 cols=36>
</TEXTAREA></td>
</tr>
</table></fieldset><br>

<tr></tr>
<tr><td ></d> <td ></d> <td ></d> <td width="500" > <center><input type='Submit' name='enviar' value = 'Guardar'></center></d>
</tr>
</table>
</form>
</div>
<?php
}
?>
  #2 (permalink)  
Antiguo 01/09/2010, 15:53
Avatar de ginitofl  
Fecha de Ingreso: diciembre-2006
Ubicación: Lima Perú
Mensajes: 349
Antigüedad: 17 años, 4 meses
Puntos: 22
Respuesta: Como verificar si un dato fue ingresado a la bd?

Hola Marinela en vez de esto:
Código PHP:
echo "<script type=\"text/javascript\">alert(\"Dantos Ingresados\");</script>"
coloca esto:

Código PHP:
if(mysql_affected_rows($con))
    { 
        ?>
        <script language="javascript">
        alert("Datos Ingresados Correctamente");
        location.href="software.php";
        </script>       
        <?    
            
    
} else 
    { 
        
?>
        <script language="javascript">
        alert("Error al Ingresar los Datos");
        setTimeout("url()",1000);
        function url()
        {
        window.history.back();
        }
        </script>       
        <? 
    
/* Cierre del else */
  #3 (permalink)  
Antiguo 01/09/2010, 16:03
Avatar de mayid
Colaborador
 
Fecha de Ingreso: marzo-2009
Ubicación: BsAs
Mensajes: 4.014
Antigüedad: 15 años
Puntos: 101
Respuesta: Como verificar si un dato fue ingresado a la bd?

Bueno, la lógica divide el script en dos:
- la parte en que se despliega un formulario
- la parte que procesa un formulario si hay contenidos para procesar.

En este caso, lo que tenes que validar es la inserción de datos. Podes usar:

Código PHP:
Ver original
  1. $result = mysql_query($sql) or die ("Error: ".mysql_error());

Eso va a detener la pagina con un error si falló la inserción.
  #4 (permalink)  
Antiguo 01/09/2010, 16:08
 
Fecha de Ingreso: agosto-2010
Mensajes: 34
Antigüedad: 13 años, 8 meses
Puntos: 0
Respuesta: Como verificar si un dato fue ingresado a la bd?

gracias¡¡¡ si me funciono...
  #5 (permalink)  
Antiguo 01/09/2010, 16:19
 
Fecha de Ingreso: agosto-2010
Mensajes: 34
Antigüedad: 13 años, 8 meses
Puntos: 0
Respuesta: Como verificar si un dato fue ingresado a la bd?

otra preguntita: como hago para que coloque un numero consecutivo, como si fuera una factura en esta parte del codigo:

<?php
if($enviar)
{
$con = mysql_connect("localhost","root","root");
mysql_select_db("laboratorio",$con);
$sql= "INSERT INTO ladpaqci (nu_paque,nu_secue,id_cds,id_softw,id_versi,nu_ser ia,nu_activ,nu_actpa,cd_ubifi) VALUES ('$nu_paque','$nu_secue','$id_cds','$id_softw','$i d_versi','" . $serial1 . "-" . $serial2 . "-" . $serial3 . "-" . $serial4 . "-" . $serial5 . "','$nu_activ','$nu_actpa','$cd_ubifi')";
$result = mysql_query($sql);

echo "<font color=Blue>el NUMERO DEL PAQUETE ingresado es: " . $nu_paque . "</font>";
echo "<font color=Blue>el NUMERO DEL PAQUETE ingresado es: " . $nu_secue . "</font>";
echo "<font color=Blue>el NUMERO DEL PAQUETE ingresado es: " . $id_cds . "</font>";
echo "<font color=Blue>el NUMERO DEL PAQUETE ingresado es: " . $id_softw . "</font>";
echo "<font color=Blue>el NUMERO DEL PAQUETE ingresado es: " . $id_versi . "</font>";
echo "<font color=Blue>el NUMERO DEL PAQUETE ingresado es: " . $nu_seria . "</font>";
echo "<font color=Blue>el NUMERO DEL PAQUETE ingresado es: " . $nu_activ . "</font>";
echo "<font color=Blue>el NUMERO DEL PAQUETE ingresado es: " . $nu_actpa . "</font>";
echo "<font color=Blue>el NUMERO DEL PAQUETE ingresado es: " . $cd_ubifi . "</font>";
?>
<center>
<h3><font color=Black><a href='nissan.html'>Aceptar</a></font></h3>
</center>
<?php
}
else
{
?>
<form name='menu' method='post' action='paquete.php'>
<table height="440"><tr><td></td>
<td><font color=Black><h5>No. PAQUETE:</font></td>
<td><input type='Text' name='nu_paque' size='6' maxlength='6'></td></tr>

<tr>
<td></td>
<td></td>
<fieldset>
<td><fieldset><legend><font color=Blue >*********</font></legend>

<fieldset><table width="158">
<tr><td width="1"></td><td width="83"><font color=Black><h6>No. SECUENCIA:</font></td>
<td width="58"><input type='Text' name='nu_secue' size='6' maxlength='6'></td>
</tr>
</table></fieldset><br>
<fieldset><table width="589">
<tr>
<td width="64" height="50" ><font color=Black>
<h6>CODIGO CD:</h6></td>
<td width="67">
<select name='id_cds' id='id_cds' onclick="cargar()">
<option value= 'N/A' >.....</option>

<?php
$con = mysql_connect("localhost","root","root");
mysql_select_db("laboratorio",$con);

$sql="select id_cds, de_obser from lamcdssf";
$respuesta= Mysql_query ($sql, $con);
while ($row= Mysql_fetch_array ($respuesta))
echo "<option value='".$row["id_cds"]."'>" . $row["de_obser"]. "</option>\n";

echo "</select>";
?>


</select></td>
<td width="114"><font color=Black><h6>CODIGO SOFTWARE:</td>
<td width="89"><input type='Text' name='id_softw' size='6' maxlength='6'></font></td>
<td width="111"><font color=Black><h6>CODIGO VERSION:</td>
<td width="116"><input type='Text' name='id_versi' size='6' maxlength='6'></font></td>
</tr>
</table></fieldset><br>
<fieldset><table width="587">
<tr>
<td width="92" height="49"><font color=Black><h6>No. ACTIVO:</font></td>
<td width="83"><select name='nu_activ' id='nu_activ' >
<option value= 'N/A' >.....</option>

<?php
$con = mysql_connect("localhost","root","root");
mysql_select_db("laboratorio",$con);

$sql="select nu_activ from lamactfi";
$respuesta= Mysql_query ($sql, $con);
while ($row= Mysql_fetch_array ($respuesta))
echo "<option value='".$row["nu_activ"]."'>" . $row["nu_activ"]. "</option>\n";

echo "</select>";
?>


</select></td>


<td width="111"><font color=Black><h6>No. ACTIVO PADRE:</font></td>
<td width="83"><select name='nu_activ' id='nu_activ' >
<option value= 'N/A' >.....</option>

<?php
$con = mysql_connect("localhost","root","root");
mysql_select_db("laboratorio",$con);

$sql="select nu_actpa from lamactfi";
$respuesta= Mysql_query ($sql, $con);
while ($row= Mysql_fetch_array ($respuesta))
echo "<option value='".$row["nu_actpa"]."'>" . $row["nu_actpa"]. "</option>\n";

echo "</select>";
?>


</select></td></tr>
</table></fieldset><br>
<fieldset><table width="584">
<tr>
<td width="115"><font color=Black><h6>UBICACION FISICA:</font></td>
<td width="36" ><input type='Text' name='cd_ubifi' size='6' maxlength='6'></td>
<td width="315"><font color=Blue><h6>A-L-C (A2LB100)</font></td>
<td width="98"><font color=Blue><h6>A: ARMARIO<BR>L: LADO<BR>C: CONSECUTIVO</font></td>
</tr>
</table></fieldset><br>
<fieldset><table width="581">
<tr>
<td width="79" height='65'><font color=Black><h6>No. SERIAL:</font></td>
<td width="490"><input name='serial1' type='text' size='5' maxlength='5'>
<input name='serial2' type='text' size='5' maxlength='5'>
<input name='serial3' type='text' size='5' maxlength='5'>
<input name='serial4' type='text' size='5' maxlength='5'>
<input name='serial5' type='text' size='5' maxlength='5'></td>

</tr>

<tr>
<td ></d> <td > <center><input type='Submit' name='enviar' value = 'Adicionar'></center></d>
</tr>
</table></fieldset></fieldset>
</td></tr>
<tr></tr>
<tr><td ></d> <td ></d> <td ></d> <td width="62" > <center><input type='Submit' name='enviar' value = 'Guardar'></center></d>
<td width="0" ></d><td width="17" height='85' ></d></tr>
</table>
</form>
</div>
<?php
}
?>
  #6 (permalink)  
Antiguo 01/09/2010, 16:58
Avatar de mayid
Colaborador
 
Fecha de Ingreso: marzo-2009
Ubicación: BsAs
Mensajes: 4.014
Antigüedad: 15 años
Puntos: 101
Respuesta: Como verificar si un dato fue ingresado a la bd?

Numero consecutivo? Es decir, sabiendo cuantos registros tenes en base de datos, sumarle uno? Eso se logra con una consulta a base de datos, y un conteo.

Etiquetas: bd, dato, fue, verificar
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 04:54.