Ver Mensaje Individual
  #9 (permalink)  
Antiguo 07/02/2007, 12:35
servco
 
Fecha de Ingreso: enero-2007
Mensajes: 13
Antigüedad: 17 años, 3 meses
Puntos: 0
Re: como puedo evitar repetir la introduccion de datos en mysql

gracias por sus sugerencias!!!

e tomado de todos y pude lograr mi objetivo, lo que hice fue que comverti el campo en "unique" asi ya no habia manera de que se repietiera el dato, utilice sesiones para guardar 1 variable para que puediera hacer una comparacion con pagina siguente ya que al introducir 1 dato aumenta las filas, condicione con un "if" al ser iguales marca error, y diferente te dice q si se introdujo el dato en la BD, les comparto el scrpit, son 3 paginas:
-----uno.php------
<?php
session_start()
?>

<html>
<head>
<title></title>
</head>

<body>
<form id="form1" name="form1" method="get" action="dos.php">

<table width="620" height="33" border="1">
<tr>
<td width="144"><input type="text" name="dato" /></td>
<td width="82"><?php
$link = mysql_connect("localhost", "root", "password");
//selecciona base de datos
mysql_select_db("base_datos", $link);
//selecciona tabla
$result = mysql_query("SELECT * FROM tabla", $link);
//adquiere numeros en la variable
$num_rows1 = mysql_num_rows($result);

session_register("num_rows1");
echo "$num_rows1 Rows\n";
?>

</td>
<td width="372"><input type="submit" name="Submit" value="Submit" /></td>
</tr>
</table>
</form>
</body>
</html>

----dos.php----------------
<?php
session_start()
?>
<?php
include("conexion.php");
$query = "INSERT INTO tabla ( dato ) VALUES ('".$dato."')";
$res = mysql_query($query);
$usuarioid = mysql_insert_id();

?>


<html>
<head>

<title></title>
</head>

<body>
<?php
echo "$num_rows1 Rows";


?>

<?php
$link = mysql_connect("localhost", "root", "password");
mysql_select_db("base_dato", $link);
$result = mysql_query("SELECT * FROM tabla", $link);
$num_rows2 = mysql_num_rows($result);



echo ("<p></p>");
echo "$num_rows2 Rows\n";

if ($num_rows1 == $num_rows2)
{
echo ("<p>no inserto dato en la BD </p>");
}
else
{
if ($num_rows1 != $num_rows2)
{
echo ("<p>insersion correcta </p>");
}
}
?>


</body>
</html>

---------------conexion.php------------------
<?

$hostname="localhost";
$username="root";
$password="";
$dbname="mantto";


mysql_connect($hostname,$username, $password) OR DIE ("<html><script language='JavaScript'>window.location.href ='error.php?err=bd'</script></html>");
mysql_select_db($dbname) or DIE ("<html><script language='JavaScript'>window.location.href = 'error.php?err=bd'</script></html>");
?>