Jump to content

simple problem, but i don find it...


spanienfoeck

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.