Pagina 1 di 5 1 2 3 ... ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 48
  1. #1
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,804

    estrarre l email da due tabelle con le funzioni

    salve siccome che e da poco che ho iniziato a usare le funzioni , ho fatto uno script , dove da una tabella trabite l id devo risalire all email , impratica un unica funzione , adesso ho provato a scrivere cosi ma mi da errore
    Codice PHP:



    $estrazione_ticketuser 
    mysql_query("
    SELECT * 
    FROM ticket_message 
    WHERE ticketid = "
    $id_ticket ."
    OR userid = 1 
    OR staffid = 1 
    OR adminid = 1 
    "
    );//da guardare

    $row   mysql_fetch_array($estrazione_ticketuser);

    echo 
    $userid  intval($row['userid']);
    echo 
    $staffid intval($row['staffid']);
    echo 
    $adminid intval($row['adminid']);




    function 
    Autormessage($userid $staffid$adminid)
    {
    if(
    $userid != 0){

    $estrazione_user mysql_query("SELECT * FROM user           WHERE id ='".$userid."'  AND stato 1   LIMIT 1");
    while(
    $row mysql_fetch_array($estrazione_user)){

          return 
    $row['emeil'];

        }
    }else if(
    $staffid != 0){

    $estrazione_staff mysql_query("SELECT * FROM staff          WHERE id ='".$staffid."' AND stato 1   LIMIT 1");
    while(
    $row mysql_fetch_array($estrazione_staff)){

          return 
    $row['emeil'];

        }
    }else if(
    $adminid != 0){

    $estrazione_admin  mysql_query("SELECT * FROM amministrator  WHERE id ='".$adminid."' AND stato 1   LIMIT 1");
    while(
    $row mysql_fetch_array($estrazione_admin)){

          return 
    $row['emeil'];

        }
    }
    else
    {
    return 
    false;
    }

    }

    $Autormessageemail Autormessage($userid $staffid$adminid);
    echo 
    $Autormessageemail 
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  2. #2
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,804
    buon giorno a tutti , ho scritto questa funzione , pero mi da un errore mysql_fetch_array perche?
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  3. #3
    l'erroe è nella query della function, tu hai messo

    Codice PHP:
    $estrazione_user mysql_query("SELECT * FROM user           WHERE id ='".$userid."'  AND stato 1   LIMIT 1");
    while(
    $row mysql_fetch_array($estrazione_user)){ 
    non volevi mica mettere

    Codice PHP:
    $estrazione_user mysql_query("SELECT * FROM user           WHERE id ='".$userid."'  AND stato=1   LIMIT 1");
    while(
    $row mysql_fetch_array($estrazione_user)){ 
    e poi, di solito i campi ID sono numerici, e tu hai messo $userid far apici il che vuole dire che MySQL presuppone che $userid sia un valore stringa: è giusto?

  4. #4
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,804
    ciao , ti spiego e propio il ciclo while che mi da errore , dovrei fare un unica funzione che controlli nella tabella del messaggio la ci stanno tre campi id user id staff id admin se uno di quest e uno dovrebbe estrarre l email se l id user e 1 controlla nella tabella user se l id staff e uno controlla la tab staff ecc
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  5. #5
    prima di tutto controlla quel che hos critto prima; in secundis, noto che usi per un if nidificato "else<spazio>if": anche questo è un errore! l'istruzione corretta è "elseif" tutto attaccato..
    in tertium l'errore in mysql_fetch_array potrebbe venire proprio da questo errore di sintassi perchè il ciclo if nels econdo e terzo caso non verrà mai eseguito essendoci un errore.
    quarto, am questa è uan raccomandazione: per i nomi delle variabili non usare nomi come

    $Autormessageemail

    che non sono molto leggibili, bensì usa la notazione camel:

    $autorMessageEmail

    è molto più comprensibile no? prima lettera minuscola, poi metti maiuscole le letetre iniziali delle altre parole che compongono il nome.

  6. #6
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,804
    mi da ugualmente errore questo:
    codice:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Programmi\Apache Software Foundation\Apache2.2\htdocs\supp\modules\viewticket\index.php on line 157

    e questo e lo script
    Codice PHP:

    $estrazione_ticketuser 
    mysql_query("
    SELECT * FROM ticket_message WHERE ticketid = '"
    $id_ticket ."' ");//da guardare
    $row mysql_fetch_array($estrazione_ticketuser);
    $userid  intval($row['userid']);
    $staffid intval($row['staffid']);
    $adminid intval($row['adminid']);




    function 
    Autormessage($userid $staffid$adminid)
    {
    if(
    $userid == 1){

    $estrazione_user  mysql_query("SELECT * FROM user           WHERE id ='".$userid."'  AND stato 1   LIMIT 1");
    while(
    $aut mysql_fetch_array($estrazione_user)){
    echo 
    $aut['email'];
    }

    }else if(
    $staffid == 1){

    $estrazione_staff  mysql_query("SELECT * FROM staff          WHERE id ='".$staffid."' AND stato 1   LIMIT 1");
    while(
    $aut mysql_fetch_array($estrazione_staff)){
    echo 
    $aut['email'];
    }

    }else if(
    $adminid == 1){

    $estrazione_admin   mysql_query("SELECT * FROM amministrator  WHERE id ='".$adminid."' AND stato 1   LIMIT 1");
    while(
    $aut mysql_fetch_array($estrazione_admin)){
    echo 
    $aut['email'];
    }

    }else
    {
    return 
    false;
    }
    }
    $autorMessageEmail Autormessage($userid $staffid$adminid);
    echo 
    $autorMessageEmail 
    l errore e al primo ciclo while
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  7. #7
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,804
    secondo voi dov e l errore ? ho provato a fare anche cosi:

    Codice PHP:
    $estrazione_ticketuser mysql_query("
    SELECT * FROM ticket_message WHERE ticketid = '"
    $id_ticket ."' OR userid = 1 OR staffid = 1 OR adminid = 1 ");//da guardare
    $row mysql_fetch_array($estrazione_ticketuser);
    $userid  intval($row['userid']);
    $staffid intval($row['staffid']);
    $adminid intval($row['adminid']);




    function 
    Autormessage($userid $staffid$adminid)
    {
    if(
    $userid != 0){
                   function 
    user($userid)
                   {
    $estrazione_user  mysql_query("SELECT * FROM user           WHERE id = ".$userid."  AND stato 1   LIMIT 1");
    $aut mysql_fetch_array($estrazione_user);
    echo 
    $aut['email'];
                   }

    }else if(
    $staffid != 0){
                   function 
    staff($staffid)
                   {
    $estrazione_staff  mysql_query("SELECT * FROM staff          WHERE id = ".$staffid." AND stato 1   LIMIT 1");
    $aut mysql_fetch_array($estrazione_staff);
    echo 
    $aut['email'];
                   }

    }else if(
    $adminid != 0){
                   function 
    admin($adminid)
                   {
    $estrazione_admin   mysql_query("SELECT * FROM amministrator  WHERE id = ".$adminid." AND stato 1   LIMIT 1");
    $aut mysql_fetch_array($estrazione_admin);
    echo 
    $aut['email'];
                   }

    }else
    {
    return ;
    }
    }
    $autorMessageEmail Autormessage($userid $staffid$adminid);
    echo 
    $autorMessageEmail
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  8. #8
    Utente di HTML.it L'avatar di Virus_101
    Registrato dal
    Sep 2008
    Messaggi
    2,497
    allora il problema del fetch array e' che la risorsa resitutita dalla funzione mysql_query non e' una risorsa mysql.

    In pratica da quello che ho visto c' dovrebbe essere un errore non tracciato nella query.

    Quando esegui le query e' sempre buona norma tenere tracia se la query viene eseguita correttemente o no.

    Esempio

    Codice PHP:
    $q =" select * from tabella where id='".$id."' AND filtro=1 order by colonna asc limit 0,10";

    /*
    Ora hai 2 modi per controllare l'errore
    1) il modo piu' veloce ma meno controllabile
    */

    $ris mysql_query($q) or die("ERRORE DI QUERY :".mysql_error() );

    /*2)UN controllo un poco piu' avanzato che nn termina l'esecuzione della pagina*/
    $dati =null;
    if( 
    $ris =@mysql_query($q)  )
    {
         
    /*
         codice di gestione risultato
         ESEMPIO :
         */
         
    while($curr mysql_fetch_array($ris))
              echo 
    "".$curr[id]." ---".$curr[filtro]."
    "
    ;
    }
    else
         echo 
    "ERRORE : ".mysql_error(); 

    Inoltre e' vero che se l'id e' numrico e' bene non metterlo tra apici in quanto mysql lo puo' veder come stringa invece che come numero. Ma e' anche vero che se non ci sono controlli preliminari se metti una stringa al posto di un numero la query fallisce brutalmente dando errori.
    Li sta al programmatore scegliere come passare i dati alla stringa di query.
    usando la funzione is_numeric o la funzione floor/ceil/abs .... si possono controllare da codice i valor del campo id anche per evitare injection tipo se uno user passasse come paramentro dell'id questa stringa? "1 OR 1=1 UNION select * from users" Potrebbero nascere pèroblemi.

    Cmq ti consiglio di inserire un controllo errore nell'esecuzione delle query che ti consenta sempre di tenere traccia di cosa si impalla e cosa no. Ovviamente poi ci si puo' costruire un logger sopra ma qui si va OT.


    EDIT :
    P.S. attento ad usare le "OR" nelle query, che come istruzioni logiche non sono esclusive per cui basta che uno dei tre casi sia vero per restituire dati.

  9. #9
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,804
    ciao ho fatto cosi ,
    Codice PHP:
    $estrazione_ticketuser mysql_query("SELECT * 
    FROM ticket_message 
    WHERE ticketid = '"
    $id_ticket ."' 
    OR userid = 1 
    OR staffid = 1 
    OR adminid = 1 
    "
    )or die("ERRORE DI QUERY TICKET MESSAGGI:".mysql_error());//da guardare
    $row mysql_fetch_array($estrazione_ticketuser);
    $userid  intval($row['userid']);
    $staffid intval($row['staffid']);
    $adminid intval($row['adminid']);


     function 
    Autormessage($userid $staffid$adminid)
    {

    if(
    $userid !=0){
    $sql "SELECT * FROM user           WHERE id = ".$userid."  AND stato 1   LIMIT 1";
    $estrazione_user  mysql_query($sql)or die("ERRORE DI QUERY USER:".mysql_error());
      if(
    $estrazione_user  mysql_query($sql))
      { 
    while(
    $curr mysql_fetch_array($estrazione_user)){
              echo 
    "".$curr['email']."";
    }
    }else{echo 
    "ERRORE DI QUERY USER BIS:".mysql_error();}
    }else if(
    $staffid !=0){
    $sql "SELECT * FROM staff          WHERE id ='".$staffid."' AND stato 1   LIMIT 1";
    $estrazione_staff  mysql_query($sql)or die("ERRORE DI QUERY STAFF:".mysql_error());
      if(
    $estrazione_staff  mysql_query($sql))
      {
    while(
    $curr mysql_fetch_array($estrazione_staff)){
              echo 
    "".$curr['email']."";
    }

    }else{echo 
    "ERRORE DI QUERY STAFF BIS:".mysql_error();}

    }else if(
    $adminid !=0){

    $sql "SELECT * FROM amministrator  WHERE id ='".$adminid."' AND stato 1   LIMIT 1";
    $estrazione_admin  mysql_query($sql)or die("ERRORE DI QUERY ADMIN:".mysql_error());
     
      if(
    $estrazione_admin  mysql_query($sql))
      {
      
    while(
    $curr mysql_fetch_array($estrazione_admin)){
              echo 
    "".$curr['email']."";
    }

    }else{echo 
    "ERRORE DI QUERY ADMIN BIS:".mysql_error();}



    }else
    {
    return 
    false;
    }
    }
    $autoreMessTicket Autormessage($userid $staffid$adminid);
    echo 
    $autoreMessTicket
    e questo e l errore :
    codice:
    ERRORE DI QUERY USER: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 '1 LIMIT 1' at line 1
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  10. #10
    Utente di HTML.it L'avatar di Virus_101
    Registrato dal
    Sep 2008
    Messaggi
    2,497
    Ecco trovato l'errore

    e' sbagliata
    SELECT * FROM user WHERE id = ".$userid." AND stato 1 LIMIT 1";


    questa e' sintatticamente corretta
    SELECT * FROM user WHERE id = ".$userid." AND stato =1 LIMIT 1";

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.