Jump to content


Photo

simple problem, but i don find it...


  • Please log in to reply
3 replies to this topic

#1 spanienfoeck

spanienfoeck
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 03 October 2006 - 10:52 AM

i want to prove if the entry allready exists... as long as there are not all fields the same it should do a new entry in the db...
can someone help me please????
cheers


$query="SELECT nombre, ultimocontacto, esde, vivido, conoces, asunto, anuncio, email, otraforma,pais 
              FROM db2006_tmp 
              WHERE nombre='$nombre'AND ultimocontacto='$ultimocontacto'AND esde='$esde'AND vivido='$vivido'AND
 	       conoces='$conoces'AND asunto='$asunto'AND anuncio='$anuncio'AND email='$email'AND
	       otraforma='$otraforma'AND pais='$pais'";

	$res =mysql_query($query);
	$found = mysql_num_rows($res);

	mysql_query("");

	if ($found == 0) {
	mysql_query("INSERT INTO db2006 (nombre, ultimocontacto, esde, vivido, conoces, asunto,
		anuncio, email, otraforma, timestamp, pais) 
		values ('$nombre','$ultimocontacto','$esde','$vivido','$conoces','$asunto', '$anuncio','$email','$otraforma','$timestamp','$pais');");

	print "OK, saved...";}

 	else {
	print "allready in list";}


#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 03 October 2006 - 11:00 AM

You don't say why you think there is a problem, but you have an extra call the mysql_query.

Here's how I would write your code:
<?php
$query="SELECT * 
              FROM db2006_tmp 
              WHERE nombre='$nombre'AND ultimocontacto='$ultimocontacto'AND esde='$esde'AND vivido='$vivido'AND
 	       conoces='$conoces'AND asunto='$asunto'AND anuncio='$anuncio'AND email='$email'AND
	       otraforma='$otraforma'AND pais='$pais'";
$q2 = "INSERT INTO db2006 (nombre, ultimocontacto, esde, vivido, conoces, asunto,
	anuncio, email, otraforma, timestamp, pais) 
	values ('$nombre','$ultimocontacto','$esde','$vivido','$conoces','$asunto', 
                   '$anuncio','$email','$otraforma','$timestamp','$pais')";

$res = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error());
$found = mysql_num_rows($res);
if ($found == 0) {
        $r2 = mysql_query($q2) or die("Problem with insert, query: $q2<br>" . mysql_error());
	echo "OK, saved...";}
else echo "allready in list";
?>

Ken

#3 spanienfoeck

spanienfoeck
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 03 October 2006 - 11:18 AM

thx, i'll try it.

the problem is, that it doesn't do what i want :-) like, if i press the verifylink, the program should prove if the same entry is allready in the .tmp database, if not it should write it in the maindatabase and delete the .tmpdatabase entry...
you get the idea? very simple....
but with my old code i got sometimes an entry in the .tmpdatabase, but most times i don't get any entry in none of the databases, and sometimes i got the same entry all the time... i doesn't prove if the same entry is allready in the database.

cheers


#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 03 October 2006 - 11:36 AM

Can we see the code of what you're describing?

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users