Visualizzazione dei risultati da 1 a 7 su 7

Discussione: Errore su controllo if

  1. #1
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560

    Errore su controllo if

    ciao,

    se esiste $credit va alla pagina aaaa.php altrimenti elabora il resto del codice.
    Mi da questo errore come mai?

    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 ''3','0','FREE','Yes',NOW(),15,'','',,)' at line 2

    ho inserito il codice correttamente tra le due parentesi graffe dopo else...

    Codice PHP:
    $creditsql "select * from accounting where mid = ".$_SESSION['memberID'];
      
    $creditR mysql_query($creditsql,$myconn) or die(mysql_error());
      
    $credit mysql_fetch_assoc($creditR);
        if (
    $credit){
        
    header("Location: aaaa.php");
      }
        else {

        
    $insert "insert into accounting (`photoLimit`,`item`,`payment_gross`,`payment_status`,`active`,`payment_date`,`mid`,`title`,`description`,`days`,`numCredit`) 
                            values ("
    .$credit['photoLimit'].",'3','0','FREE','Yes',NOW(),".$_SESSION['memberID'].",'".$credit['title']."','".$credit['description']."',".$credit['days'].",".$credit['numCredit'].")";
        
    //echo $insert;
        
    mysql_query($insert,$myconn) or die(mysql_error());
        
        
    $updateSQL sprintf("UPDATE members SET `expires`=DATE_ADD(NOW(), INTERVAL ".$credit['days']." DAY) WHERE id=%s",
                                      
    $_SESSION['memberID']);

                           
    mysql_query($updateSQL,$myconn) or die(mysql_error());
                           
        
    $insertGoTo "a_index.php";
        
    header(sprintf("Location: %s"$insertGoTo));
        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;
    }


  2. #2
    Utente di HTML.it L'avatar di hyde82
    Registrato dal
    Feb 2010
    Messaggi
    243
    l'errore è la query....

  3. #3
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    senza if e else funziona la query,
    solo con

    Codice PHP:
    $insert "insert into accounting (`photoLimit`,`item`,`payment_gross`,`payment_status`,`active`,`payment_date`,`mid`,`title`,`description`,`days`,`numCredit`) 
                            values ("
    .$credit['photoLimit'].",'3','0','FREE','Yes',NOW(),".$_SESSION['memberID'].",'".$credit['title']."','".$credit['description']."',".$credit['days'].",".$credit['numCredit'].")";
        
    //echo $insert;
        
    mysql_query($insert,$myconn) or die(mysql_error());
        
        
    $updateSQL sprintf("UPDATE members SET `expires`=DATE_ADD(NOW(), INTERVAL ".$credit['days']." DAY) WHERE id=%s",
                                      
    $_SESSION['memberID']);

                           
    mysql_query($updateSQL,$myconn) or die(mysql_error());
                           
        
    $insertGoTo "a_index.php";
        
    header(sprintf("Location: %s"$insertGoTo));
        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;

    funziona... com'è possibile?

  4. #4
    Utente di HTML.it L'avatar di hyde82
    Registrato dal
    Feb 2010
    Messaggi
    243
    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 ''3','0','FREE','Yes',NOW(),15,'','',,)' at line 2
    ehy amico questo è un errore di "mysql"....e ti dice anche dove...la struttura di controllo non c'entra nulla...

  5. #5
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    ho capito ci voleva

    $credit3 = mysql_fetch_assoc($creditR);
    if ($credit3){

    e non $credit perchè si ripeteva nell insert

    grazie

  6. #6
    Utente di HTML.it L'avatar di hyde82
    Registrato dal
    Feb 2010
    Messaggi
    243
    e poi guardando il codice noto che la seconda query implica che la prima sia stata già eseguita....

    perchè l'array $credit[] che usi nella "insert" è la risultanza di:

    $creditsql = "select * from accounting where mid = ".$_SESSION['memberID']; $creditR = mysql_query($creditsql,$myconn) or die(mysql_error()); $credit = mysql_fetch_assoc($creditR);

  7. #7
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    si deve funzionare così... funziona correttamente ora, grazie

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.