Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    Nov 2004
    Messaggi
    18

    Problema Mysql - Sovrapposizione voto

    Ciao a tutti, scrivo questo post perchè ho un problema con un mio script php.
    Ciò su cui sbatto la testa ormai da qualche giorno è questo:

    Ho uno script cui vengono recensite alcune cose e questi possono essere votati dagli utenti. Ma il problema è che votando la stessa persona più volte, il voto che viene registrato è solo l'ultimo e quello precedente viene cancellato. In parole povere: io voto, poi rivoto di nuovo e il sito mi registra il nuovo messaggio lasciato e cancella quello precedente. Alla fine anzichè avere due voti ne ho soltanto uno....!!Il problema è sicuramente nella dichiarazione fatta dal database....Ma non so come metterci mano. Vi posto la tabella del database riguardante la parte dei voti e se potete mi dite cosa fare. Vi ringrazio infinitamente per le vostre eventuali risposte. Ciao!

    ________________________

    -- phpMyAdmin SQL Dump
    -- version 2.9.1
    -- http://www.phpmyadmin.net
    --
    -- Host: localhost
    -- Generato il: 14 Apr, 2007 at 11:26 AM
    -- Versione MySQL: 4.1.22
    -- Versione PHP: 4.4.6RC2-dev
    --
    -- Database: `my_adsattack`
    --

    -- --------------------------------------------------------

    --
    -- Struttura della tabella `hl_votes`
    --

    CREATE TABLE `hl_votes` (
    `id` bigint(20) unsigned NOT NULL auto_increment,
    `listing_id` bigint(20) unsigned default NULL,
    `vote` tinyint(1) unsigned default '0',
    `date` datetime default NULL,
    `comment` varchar(255) default NULL,
    `email` varchar(255) default NULL,
    `ip` varchar(20) default NULL,
    `confirm` varchar(255) NOT NULL default '0',
    PRIMARY KEY (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

    --
    -- Dump dei dati per la tabella `hl_votes`
    --

    INSERT INTO `hl_votes` (`id`, `listing_id`, `vote`, `date`, `comment`, `email`, `ip`, `confirm`) VALUES
    (1, 1, 2, '2007-04-14 00:11:50', 'Thanks for all!', 'xxxxxx@gmail.com', '83.187.xxx.xxx', '0');

    ____________________________


    Se vi serve altro ditemi pure che io la posto!Grazie mille!

  2. #2
    Utente di HTML.it L'avatar di luca200
    Registrato dal
    Apr 2002
    Messaggi
    4,120
    Bisognerebbe sapere anche come lavora il codice, su questa tabella.
    Come viene identificato l'utente? In base alla email? Evidentemente allora verrà fatto un controllo se quell'indirizzo ha già votato e in quel caso fa un UPDATE invece che INSERT.

  3. #3
    Utente di HTML.it
    Registrato dal
    Nov 2004
    Messaggi
    18
    Praticamente il sistema funziona così. Ogni utente (ovvero ogni email) può votare ogni 24 ore....Dimmi se vuoi la query di ogni parte della tabella hl_votes e la metto qua

  4. #4
    Utente di HTML.it
    Registrato dal
    Nov 2004
    Messaggi
    18
    Mi sa che sto uscendo pazzo....vi posto la parte di script in php che dovrebbe collegarsi al database mysql per la query


    Codice PHP:
    <?
    /***********************************************************************/
    /*                                                                     */
    /*  This file is created by deZender                                   */
    /*                                                                     */
    /*  deZender (Decoder for Zend Encoder/SafeGuard):                     */
    /*    Version:      0.9.3.0                                            */
    /*    Author:       qinvent.com                                        */
    /*    Release on:   2005.11.12                                         */
    /*                                                                     */
    /***********************************************************************/


      
    if ($frm['action'] == 'confirm')
      {
        
    $success 0;
        if (
    $frm['code'])
        {
          
    $q 'select * from hl_votes where confirm = \'' quote ($frm['code']) . '\' limit 0, 1';
          
    $sth mysql_query ($q);
          
    $row mysql_fetch_array ($sth);
          if (
    $row['listing_id'])
          {
            
    $qupdates 0;
            
    $qt 'select id from hl_votes where confirm = \'0\' and email = \'' quote ($row['email']) . '\' and listing_id = ' $row['listing_id'];
            
    $stht mysql_query ($qt);
            while (
    $rowt mysql_fetch_array ($stht))
            {
              
    $inserts = array ();
              
    array_push ($inserts'ip = \'' $frm_env['REMOTE_ADDR'] . '\'');
              
    array_push ($inserts'comment = \'' quote ($row['comment']) . '\'');
              
    array_push ($inserts'vote = \'' $row['vote'] . '\'');
              
    array_push ($inserts'date = now()');
              
    $qu 'update hl_votes set ' join (','$inserts) . ' where id = ' $rowt['id'];
              
    mysql_query ($qu);
              ++
    $qupdates;
            }

            if (
    $qupdates)
            {
              
    $q 'delete from hl_votes where confirm = \'' quote ($frm['code']) . '\'';
              
    $sth mysql_query ($q);
              
    $success 2;
            }
            else
            {
              
    $q 'update hl_votes set confirm = \'0\' where confirm = \'' quote ($frm['code']) . '\'';
              
    $sth mysql_query ($q);
              
    $success 1;
            }
          }
        }

        
    $smarty->assign ('listing_id'$row['listing_id']);
        
    $smarty->assign ('success'$success);
        
    $smarty->display ('vote_confirmed.tpl');
        exit ();
      }

      
    $frm['lid'] = intval ($frm['lid']);
      if (
    $frm['lid'])
      {
        
    $q 'select * from hl_listings where id = ' $frm['lid'];
        
    $sth mysql_query ($q);
        
    $listing mysql_fetch_array ($sth);
        if (!
    $listing)
        {
          
    header ('Location: ?a=home');
          exit ();
        }
      }

      
    $smarty->assign ('listing'$listing);
      if (
    $frm['display'] == 'confirm')
      {
        
    $smarty->display ('vote_confirm.tpl');
      }
      else
      {
        if (
    $frm['display'] == 'accepted')
        {
          
    $smarty->display ('vote_accepted.tpl');
        }
        else
        {
          if (
    $frm['action'] == 'save')
          {
            
    $frm['vote'] = intval ($frm['vote']);
            if (
    $frm['vote'] < 0)
            {
              
    $frm['vote'] = 0;
            }

            if (
    $frm['vote'])
            {
              
    $frm['vote'] = 3;
            }

            
    $inserts = array ();
            
    array_push ($inserts'listing_id = \'' $frm['lid'] . '\'');
            
    array_push ($inserts'ip = \'' $frm_env['REMOTE_ADDR'] . '\'');
            
    array_push ($inserts'email = \'' quote ($frm['email']) . '\'');
            
    array_push ($inserts'comment = \'' quote ($frm['comment']) . '\'');
            
    array_push ($inserts'vote = \'' $frm['vote'] . '\'');
            
    array_push ($inserts'date = now()');
            
    $confirm_code gen_confirm_code (10);
            if (
    $settings['vote_confirmation_require'])
            {
              
    array_push ($inserts'confirm = \'' $confirm_code '\'');
              
    $q 'insert into hl_votes set ' join (','$inserts);
            }
            else
            {
              
    $qvotes 0;
              
    $qt 'select id from hl_votes where confirm = \'0\' and  email = \'' quote ($frm['email']) . '\' and listing_id = ' $frm['lid'];
              
    $sth mysql_query ($qt);
              while (
    $row mysql_fetch_array ($sth))
              {
                
    $q 'update hl_votes set ' join (','$inserts) . ' where id = ' $row['id'];
                ++
    $qvotes;
                
    $success 2;
              }

              if (
    $qvotes == 0)
              {
                
    $q 'insert into hl_votes set ' join (','$inserts);
                
    $success 1;
              }
            }

            
    $sth mysql_query ($q);
            if (
    $settings['vote_confirmation_require'])
            {
              
    $info = array ();
              
    $info['confirm_code'] = $confirm_code;
              
    $info['listing_name'] = $listing['name'];
              
    send_mail ('vote_confirm'$frm['email'], $settings['system_email'], $info);
              
    header ('Location: ?a=add_vote&lid=' $frm['lid'] . '&display=confirm');
            }
            else
            {
              
    header ('Location: ?a=add_vote&lid=' $frm['lid'] . ('' '&display=accepted&success=' $success));
            }
          }
        }
      }

    ?>

  5. #5
    Utente di HTML.it
    Registrato dal
    Nov 2004
    Messaggi
    18
    Nessun consiglio sul da farsi?

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 © 2024 vBulletin Solutions, Inc. All rights reserved.