Jump to content

Archived

This topic is now archived and is closed to further replies.

spanienfoeck

simple problem, but i don find it...

Recommended Posts

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

[code]

$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";}[/code]

Share this post


Link to post
Share on other sites
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:
[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";
?>[/code]

Ken

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Can we see the code of what you're describing?

Ken

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.