Visualizzazione dei risultati da 1 a 4 su 4

Discussione: Errore su MYSQL

  1. #1
    Utente di HTML.it L'avatar di kikysc
    Registrato dal
    Sep 2005
    Messaggi
    93

    Errore su MYSQL

    Ciao ragazzi,
    sto tentando di modificare una newsletter scaricata da internet e nella modifica dei dati si è creato un errore su MySQL:


    Errore
    query SQL:

    `nome``cognome``ente``email` SELECT COUNT( * ) AS `Righe` , `id`
    FROM `iscritti`
    GROUP BY `id`
    ORDER BY `id`
    LIMIT 0 , 30

    Messaggio di MySQL:

    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'nome``cognome``ente``email` SELECT COUNT( * ) AS `Righe` , `id`

    inoltre quando il form di sottoscrizione della news letter va ad effettuare l'iscrizione mi da come risultato questo messaggio:

    Column count doesn't match value count at row 1


    vi posto pure il codice così avete un quadro completo della situazione:

    codice:
    <?php require_once('newsletterconn.php'); ?>
    <?php
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
    
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    
    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
      $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    }
    
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "modulo")) {
      $insertSQL = sprintf("INSERT INTO iscritti (nome, cognme, ente, email) VALUES (%s)",
                           GetSQLValueString($_POST['nome, cognme, ente, email'], "text"));
    
      mysql_select_db($database_newsletterconn, $newsletterconn);
      $Result1 = mysql_query($insertSQL, $newsletterconn) or die(mysql_error());
    
      $insertGoTo = "grazie.php";
      if (isset($_SERVER['QUERY_STRING'])) {
        $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
        $insertGoTo .= $_SERVER['QUERY_STRING'];
      }
      header(sprintf("Location: %s", $insertGoTo));
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 2.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <link rel="stylesheet" type="text/css" href="stile.css" />
    <title>AGWS Newsletter</title>
    </head>
    <body>
    <div align="center" class="bianco"> </div>
    <div align="center" id="testata">Iscriviti alla newsletter</div>
    <div align="center" id="contenuto"> 
      <form method="POST" action="<?php echo $editFormAction; ?>" name="modulo">
        
    
        Nome: 
        <input name="nome" type="text" size="50" />
        
    
        
    
        Cognome: 
        <input name="cognome" type="text" size="50" />
        
    
        
    
        Ente appartenenza: 
        <input name="ente" type="text" size="50" />
        
    
        
    
        E-mail: 
        <input name="email" type="text" size="50" />
        
    
        
    
        <input type="submit" value="Invia" />
        <input type="hidden" name="MM_insert" value="modulo">
      </form>
    </div>
    <div align="center" class="bianco"> <a href="admin/index.php">Amministrazione 
      newsletter >></a></div>
    <div align="center" id="footer"> Sistema di gestione newsletter by <a href="http://www.agwebsolutions.it" title="Vuoi una newsletter così per il tuo sito?">AG 
      web solutions</a></div>
    </body>
    </html>
    sapete dirmi cosa è successo?
    Grazie

  2. #2
    Problema 1.
    con quella query hai fatto un grosso casino
    la versione corretta è così:

    codice:
    SELECT COUNT( * ) AS `Righe` , `id`, `nome`,`cognome`,`ente`,`email`
    FROM `iscritti`
    GROUP BY `id`
    ORDER BY `id`
    LIMIT 0 , 30
    aggiungo una considerazione. se il campo "id" è un id univoco quel "COUNT(*) AS Righe" con "GROUP BY id" restituirà sempre 1 perchè mysql andrà a contare tutti i record che hanno un id diverso, ed essendo un valore univoco restituirà sempre 1. eventuali modifiche alla query dipendono da quello che vuoi fare tu.

    Problema 2.
    probabilmente c'è una query di INSERT INTO nella quale il numero di campi dichiarati è diverso dal numero di rispettivi valori. ad esempio:

    codice:
    INSERT INTO tabella(campo1, campo2, campo3)
    VALUES('valore 1', 'valore 2')
    questa query darebbe il tipo d'errore che hai tu perchè ho dichiarato 3 campi (campo1, campo2, campo3) ma sto associando solo 2 valori.

  3. #3
    Utente di HTML.it L'avatar di kikysc
    Registrato dal
    Sep 2005
    Messaggi
    93
    Problema 1
    al valore "id" ho dato la funzione "auto_increment" (sto lavorando su un db aruba) è forse questo che mi dicevi di settare???

    Problema 2

    è un estratto del codice già postato:

    codice:
    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
      $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    }
    
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "modulo")) {
      $insertSQL = sprintf("INSERT INTO iscritti (nome, cognme, ente, email) VALUES (%s)",
                           GetSQLValueString($_POST['nome, cognme, ente, email'], "text"));
    
      mysql_select_db($database_newsletterconn, $newsletterconn);
      $Result1 = mysql_query($insertSQL, $newsletterconn) or die(mysql_error());
    
      $insertGoTo = "grazie.php";
      if (isset($_SERVER['QUERY_STRING'])) {
        $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
        $insertGoTo .= $_SERVER['QUERY_STRING'];
      }
      header(sprintf("Location: %s", $insertGoTo));
    }
    ?>
    è questo che non va??? Come dovrei impostarlo???

  4. #4
    Utente di HTML.it L'avatar di kikysc
    Registrato dal
    Sep 2005
    Messaggi
    93
    qualcuno sa aiutarmi?

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.