Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    verifica presenza record

    Codice PHP:
    $query "SELECT *
                 FROM 
    $db_name.quizgame
                 WHERE 
    $db_name.quizgame.id_user = $id_user ";
                             
        if(
    $rq mysql_query($query)){
        
            echo 
    mysql_num_rows($rq);
            if(
    mysql_num_rows($rq)==1){
                echo 
    'user found';
            }else{
                echo 
    'user not found';
                
                
    $query "INSERT INTO $db_name.quizgame (id_user, phrase, score) VALUES ('$id_user','$phrase','$score')";    
                echo 
    $query;    
                
    $rq mysql_query($query);
                    
                
            }
            
        }else{
            
    $report='query failed';
            die(
    mysql_error());
        } 
    con questo codice voglio prima verificare se un utente è presente in una tabella e successivamente inserire o fare l'update del proprio record.
    se non inserisco la seconda query, quella dopo 'user not found', la prima query funziona.
    se invece inserisco la seconda mi trova l'utente anche se nella tabella del db non c'è nessun record.

    non capisco proprio, qualcuno mi aiuta?

    grazie!!
    There is nothing conceptually better than Rock 'n' Roll.

    poker is very much like sex. most people think they're the best but don't know what they're doing.

  2. #2
    prova in questo modo:
    Codice PHP:
    <?php
    $query 
    "SELECT *
                 FROM 
    $db_name.quizgame
                 WHERE 
    $db_name.quizgame.id_user = $id_user ";
                  
    $rq mysql_query($query)
        if(
    $rq)
            {
            if(
    mysql_num_rows($rq)!=0){

                echo 
    'user found';
            }
              else{
                echo 
    'user not found';

                
    $query "INSERT INTO $db_name.quizgame (id_user, phrase, score) VALUES ('$id_user','$phrase','$score')";

                
    $rq mysql_query($query);
                echo 
    mysql_affected_rows();


            }

        }else{
            
    $report='query failed';
            echo 
    mysql_error();
        }
    ?>

  3. #3
    il codice era corretto, era un problema di visualizzazione derivato da 2 chiamate alla stessa pagina da flash.
    non vedevo quello che mi serviva perchè nel frattempo era cambiato.

    grazie comunque!

    There is nothing conceptually better than Rock 'n' Roll.

    poker is very much like sex. most people think they're the best but don't know what they're doing.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.