Problema array_key_exists!

ma è quello che ho fatto, però non conoscendo bene, anzi molto male, il php non riesco a capire dove sia il problema.
Per questo ho chiesto aiuto a voi esperti!
 
Ecco l'originale:
PHP:
<?php
/*
	Page : panier_valider.php
				Page qui envoie et confirme la commande
*/
$NumeroCommande = date("Gisdm")." - ".date("y");
$TotalCommande = 0;
//On regarde si le paramètre sont correcte
if (isset($_SESSION["commande"]["prod"])){
	if (isset($_POST["tnom"]) && isset($_POST["ttel"])){
		$headers ='From: "Au petit comestible"<[email protected]>'."\n";
		$headers .='Content-Type: text/html; charset="iso-8859-1"'."\n";
		$headers .='Content-Transfer-Encoding: 8bit';			
		$cles = array_keys($_SESSION["commande"]["prod"]);			 
		
		if (isset($_POST["tremarques"]))
			$remarques = $_POST["tremarques"];
		else
			$remarques = 'Aucune.';
		//Numéro de commande : '.$NumeroCommande.'<br />	 
		$messageclients = '<html>
						<head>
							<title>
								Votre Commande
							</title>
						</head>
						<body>
						<p>Bonjour '.$_POST["tnom"].', votre commande a bien été prise en compte : <br /><br />
							Téléphone : '.$_POST["ttel"].'<br />
							Heure de passage : '.$_POST["theureh"].'h'.$_POST["theurem"].'<br/>
							
		       	   		</p>
						<table width="600">
						  <caption style="font-size:20px;color:#000000;font-weight:bold;">Commande</caption>
						  <tr>
							 <th style="background:#FFFFFF;color:#000000;">Produit</th>
							 <th style="background:#FFFFFF;color:#000000;">Prix</th>
							 <th style="background:#FFFFFF;color:#000000;">Quantité</th>
							 <th style="background:#FFFFFF;color:#000000;">Sous total</th>
						  </tr>	';	
		$tot = 0;
		foreach($cles as $i){
			if (array_key_exists($i, $_SESSION["commande"]["prod"]))
			{
				$_SESSION["commande"]["prix"][$i] = str_replace(",", ".", $_SESSION["commande"]["prix"][$i]);
				$soustot = (float)$_SESSION["commande"]["prix"][$i] * (float)$_SESSION["commande"]["quantite"][$i];
				$_SESSION["commande"]["prix"][$i] = str_replace(".", ",", $_SESSION["commande"]["prix"][$i]);
				
				$messageclients .=  '<tr>
				              	<td style="border:#000000 solid 1px;">
									'.stripslashes($_SESSION["commande"]["prod"][$i]).'
								</td>
								<td style="text-align:right;border:#000000 solid 1px;">
									'.$_SESSION["commande"]["prix"][$i].' CHF
								</td>
								<td style="text-align:center;border:#000000 solid 1px;">
									'.$_SESSION["commande"]["quantite"][$i].'
								</td>
								<td style="text-align:right;border:#000000 solid 1px;">
									'.number_format($soustot, 2, ',', ' ').' CHF
								</td>								
							  </tr>';
				$tot += $soustot;
			}	   
		}
		$messageclients .= '</table><div style="text-align:right;margin-top:10px;width:600px;color:#000000;font-size:18px;">
						Total : '.number_format($tot, 2, ',', ' ').' CHF</div>
						<br /><br />
						Remarques : '.$remarques.'
						</body></html>';
		//Numéro de commande : '.$NumeroCommande.'<br />										  
		$message = '<html>
						<head>
							<title>
								Nouvelle commande
							</title>
						</head>
						<body>
						<p>
							Nom : '.$_POST["tnom"].'<br /> 
							Téléphone : '.$_POST["ttel"].'<br />
							Email : '.$_POST["tmail"].'<br >
							Heure de passage : '.$_POST["theureh"].'h'.$_POST["theurem"].'<br/>
							Remarques : '.$remarques.' <br />
							
		       	   		</p>
						<table width="600">
						  <caption style="font-size:20px;color:#000000;font-weight:bold;">Commande</caption>
						  <tr>
						  	 <th style="background:#FFFFFF;color:#000000;font-size:12px;">Quantité</th>
							 <th style="background:#FFFFFF;color:#000000;font-size:12px;">Produit</th>
							 <th style="background:#FFFFFF;color:#000000;font-size:12px;">Prix</th>
							 <th style="background:#FFFFFF;color:#000000;font-size:12px;">Sous total</th>
						  </tr>';
		$tot = 0;
		foreach($cles as $i){
			if (array_key_exists($i, $_SESSION["commande"]["prod"]))
			{
				$_SESSION["commande"]["prix"][$i] = str_replace(",", ".", $_SESSION["commande"]["prix"][$i]);
				$soustot = (float)$_SESSION["commande"]["prix"][$i] * (float)$_SESSION["commande"]["quantite"][$i];
				$_SESSION["commande"]["prix"][$i] = str_replace(".", ",", $_SESSION["commande"]["prix"][$i]);
				
				$message .=  '<tr>
								<td style="border:#000000 solid 1px;text-align:center;">
									'.$_SESSION["commande"]["quantite"][$i].'
								</td>
				              	<td style="border:#000000 solid 1px;">
									'.stripslashes($_SESSION["commande"]["prod"][$i]).'
								</td>
								<td style="text-align:right;border:#000000 solid 1px;">
									'.$_SESSION["commande"]["prix"][$i].' .Sfr
								</td>
								<td style="text-align:right;border:#000000 solid 1px;">
									'.number_format($soustot, 2, ',', ' ').' CHF
								</td>								
							  </tr>';
				$tot += $soustot;
			}	   
		}
		$message .= '</table><div style="text-align:right;margin-top:10px;width:600px;color:#000000;font-size:18px;">
						Total : '.number_format($tot, 2, ',', ' ').' CHF</div></body></html>';
			
		$mail = $params["mail"];
		
		if(@mail($mail, 'Commande Au petit comestible', $message, $headers) && @mail($_POST["tmail"], 'Commande Au petit comestible', $messageclients, $headers))
		{
			  echo '<br />Commande envoyée! Un Email de confirmation a été envoyé à l\'adresse : '.$_POST["tmail"].'.<div class="spa"></div>';

			  $sqlcommande = "INSERT INTO tstat (idstat, datecommande, champtype, description, prix) VALUES "; 
			  			  
			  foreach($cles as $i)
			  {
			  	if (array_key_exists($i, $_SESSION["commande"]["type"]) && $_SESSION["commande"]["type"] != NULL)
			  	{
			  		for ($j = 0; $j < $_SESSION["commande"]["quantite"][$i]; $j++)
			  		{		  			
				  		$desc = str_replace("<br />", " - ", $_SESSION["commande"]["prod"][$i]);
				  		$desc = strip_tags($desc);			  		
				  		$sqlcommande .= " ('', '".date("Y-m-d")."', '".$_SESSION["commande"]["type"][$i]."', '".addslashes($desc)."',".number_format((float)$_SESSION["commande"]["prix"][$i], 2, '.', ' ').")"; 		  
				  	}
			  	 }
			  }
			  
			  $sqlcommande = substr($sqlcommande, 0, strlen($sqlcommande)-1);
			  $sqlcommande .= ";";			  		  
			  mysql_query($sqlcommande) or die ("Erreur SQL > ".$sqlcommande."<br />".mysql_error()); 	
 
			  unset($_SESSION["commande"]);
		}
		else
			echo '<br />Erreur répéter l\'opération.<div class="spa"></div>';
	}
}

?>
 
Io ho aggiunto il form PAYPAL e un altro form per la mailing-list.
Ma se li tolgo il problema permane...aaaaaahhhh!!!!
 
ciao
ma l'originale funzionava?
sei sicuro che avendo tolto quello che hai messo di non aver tolto qulcos'altro? alle volte basta una quisquiglia e tutto va in pallino
 
Forse ho piazzato male i form?
PHP:
<?php
/*
        Page : panier_valider.php
                                Page qui envoie et confirme la commande
*/      
$NumeroCommande = date("Gisdm")." - ".date("y");
$TotalCommande = 0;
//On regarde si le paramètre sont correcte
if (isset($_SESSION["commande"]["prod"])){
        if (isset($_POST["tnom"]) && isset($_POST["ttel"])){
                $headers ='From: "Au petit comestible"<[email protected]>'."\n";
                $headers .='Content-Type: text/html; charset="iso-8859-1"'."\n";
                $headers .='Content-Transfer-Encoding: 8bit';                   
                $cles = array_keys($_SESSION["commande"]["prod"]);                       
                
                if (isset($_POST["tremarques"]))
                        $remarques = $_POST["tremarques"];
                else
                        $remarques = 'Aucune.';
                //Numéro de commande : '.$NumeroCommande.'<br />         
                $messageclients = '<html>
                                                <head>
                                                        <title>
                                                                Votre Commande
                                                        </title>
                                                </head>
                                                <body>
                                                <p>Bonjour '.$_POST["tnom"].', votre commande a bien été prise en compte : <br /><br />
                                                        Téléphone : '.$_POST["ttel"].'<br />
                                                        Heure de passage : '.$_POST["theureh"].'h'.$_POST["theurem"].'<br/>
                                                        
                                        </p>
                                                <table width="600">
                                                  <caption style="font-size:20px;color:#000000;font-weight:bold;">Commande</caption>
                                                  <tr>
                                                         <th style="background:#FFFFFF;color:#000000;">Produit</th>
                                                         <th style="background:#FFFFFF;color:#000000;">Prix</th>
                                                         <th style="background:#FFFFFF;color:#000000;">Quantité</th>
                                                         <th style="background:#FFFFFF;color:#000000;">Sous total</th>
                                                  </tr> ';      
                $tot = 0;
                foreach($cles as $i){
                        if (array_key_exists($i, $_SESSION["commande"]["prod"]))
                        {
                                $_SESSION["commande"]["prix"][$i] = str_replace(",", ".", $_SESSION["commande"]["prix"][$i]);
                                $soustot = (float)$_SESSION["commande"]["prix"][$i] * (float)$_SESSION["commande"]["quantite"][$i];
                                
                                
                                $messageclients .=  '<tr>
                                                <td style="border:#000000 solid 1px;">
                                                                        '.stripslashes($_SESSION["commande"]["prod"][$i]).'
                                                                </td>
                                                                <td style="text-align:right;border:#000000 solid 1px;">
                                                                        '.$_SESSION["commande"]["prix"][$i].' CHF
                                                                </td>
                                                                <td style="text-align:center;border:#000000 solid 1px;">
                                                                        '.$_SESSION["commande"]["quantite"][$i].'
                                                                </td>
                                                                <td style="text-align:right;border:#000000 solid 1px;">
                                                                        '.number_format($soustot, 2, ',', ' ').' CHF
                                                                </td>                                                           
                                                          </tr>';
                                $tot += $soustot;
                        }          
                }
                $messageclients .= '</table><div style="text-align:right;margin-top:10px;width:600px;color:#000000;font-size:18px;">
                                                Total : '.number_format($tot, 2, ',', ' ').' CHF</div>
                                                <br /><br />
                                                Remarques : '.$remarques.'
                                                </body></html>';
                //Numéro de commande : '.$NumeroCommande.'<br />                                                                                  
                $message = '<html>
                                                <head>
                                                        <title>
                                                                Nouvelle commande
                                                        </title>
                                                </head>
                                                <body>
                                                <p>
                                                        Nom : '.$_POST["tnom"].'<br /> 
                                                        Téléphone : '.$_POST["ttel"].'<br />
                                                        Email : '.$_POST["tmail"].'<br >
                                                        Heure de passage : '.$_POST["theureh"].'h'.$_POST["theurem"].'<br/>
                                                        Remarques : '.$remarques.' <br />
                                                        
                                        </p>
                                                <table width="600">
                                                  <caption style="font-size:20px;color:#000000;font-weight:bold;">Commande</caption>
                                                  <tr>
                                                         <th style="background:#FFFFFF;color:#000000;font-size:12px;">Quantité</th>
                                                         <th style="background:#FFFFFF;color:#000000;font-size:12px;">Produit</th>
                                                         <th style="background:#FFFFFF;color:#000000;font-size:12px;">Prix</th>
                                                         <th style="background:#FFFFFF;color:#000000;font-size:12px;">Sous total</th>
                                                  </tr>';
                $tot = 0;
                foreach($cles as $i){
                        if (array_key_exists($i, $_SESSION["commande"]["prod"]))
                        {
                                $_SESSION["commande"]["prix"][$i] = str_replace(",", ".", $_SESSION["commande"]["prix"][$i]);
                                $soustot = (float)$_SESSION["commande"]["prix"][$i] * (float)$_SESSION["commande"]["quantite"][$i];
                                //$_SESSION["commande"]["prix"][$i] = str_replace(".", ",", $_SESSION["commande"]["prix"][$i]);//
                                
                                $message .=  '<tr>
                                                                <td style="border:#000000 solid 1px;text-align:center;">
                                                                        '.$_SESSION["commande"]["quantite"][$i].'
                                                                </td>
                                                <td style="border:#000000 solid 1px;">
                                                                        '.stripslashes($_SESSION["commande"]["prod"][$i]).'
                                                                </td>
                                                                <td style="text-align:right;border:#000000 solid 1px;">
                                                                        '.$_SESSION["commande"]["prix"][$i].' 
                                                                </td>
                                                                <td style="text-align:right;border:#000000 solid 1px;">
                                                                        '.number_format($soustot, 2, ',', ' ').' CHF
                                                                </td>                                                           
                                                          </tr>';
                                $tot += $soustot;
                        }          
                }
                $message .= '</table><div style="text-align:right;margin-top:10px;width:600px;color:#000000;font-size:18px;">
                                                Total : '.number_format($tot, 2, ',', ' ').' CHF</div></body></html>';
                        
                $mail = $params["mail"];
                
                if(@mail($mail, 'Commande Au petit comestible', $message, $headers) && @mail($_POST["tmail"], 'Commande Au petit comestible', $messageclients, $headers));
                
                

    
        
                {
                          echo '<br /><div style="text-align:center;margin-top:10px;width:650px;color:#4b4c38;font-size:18px;"><b>Commande envoyée!</b><br /> Un e-mail de confirmation a été envoyé à l\'adresse :<br /><br /><i> '.$_POST["tmail"].'</i></div>'; 
                                                    
                          
                          echo  
                          '<div class="paypal">
                            <p>Si vous souhaitez payer à l\'avance par carte de crédit, cliquez ici:</p>
                            <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
                            <input type="hidden" name="cmd" value="_cart">
                            <input type="hidden" name="business" value="[email protected]">
                            <input type="hidden" name="lc" value="CH">
                            <input type="hidden" name="item_name" value="Commande">
                            <input type="hidden" name="amount" value="'.$tot.'">
                            <input type="hidden" name="currency_code" value="CHF">
                            <input type="hidden" name="button_subtype" value="products">
                            <input type="hidden" name="no_note" value="0">
                            <input type="hidden" name="add" value="1">
                            <input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_LG.gif:NonHostedGuest">
                            <input type="image" src="https://www.paypalobjects.com/fr_FR/CH/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - la solution de paiement en ligne la plus simple et la plus sécurisée !">
                            <img alt="" border="0" src="https://www.paypalobjects.com/fr_FR/i/scr/pixel.gif" width="1" height="1">
                            </form>
                           <br /> 
                           <br />
                           <br />                           
                            <div class="iscrizione2">
                            <table>
                            <tr><td><img src="Images/Design/news.png"></td>
                            <td>      
                            <form action="http://admin.infomaniak.com/mail/mailinglist_process.php" method="POST"> 
                            <b>Inscrivez-vous</b> gratuitement à notre news-letter pour recevoir les actualités de la semaine!<br />
                            Insérez votre adresse e-mail ici:
                            <input type="hidden" name="maillist" value="bmV3c2xldHRlckBhdXBldGl0Y29tZXN0aWJsZS5uZXQ="> 
                            <input type="text" name="email">
                            <input type="hidden" name="action" value="add">
                            <input type="hidden" name="url" value="http://aupetitcomestible.net/iscrizione.html">
                            <input type="submit" name="add" value="Inscription">
                            </form></td></tr>
                            </table>
                            </div></div>';                         
                             
                }       
                
/* STATISTICHE     */
$sqlcommande = "INSERT INTO tstat (idstat, datecommande, champtype, description, prix) VALUES( ";			  
			  foreach($cles as $i)
			  {
			  	if (array_key_exists($i, $_SESSION["commande"]["type"]) && $_SESSION["commande"]["type"] != NULL)
			  	{
			  		for ($j = 0; $j < $_SESSION["commande"]["quantite"][$i]; $j++)
			  		{		  			
				  		$desc = str_replace("<br />", " - ", $_SESSION["commande"]["prod"][$i]);
				  		$desc = strip_tags($desc);			  		
				  		$sqlcommande .= "'', '".date("Y-m-d")."', '".$_SESSION["commande"]["type"][$i]."', '".addslashes($desc)."',".$_SESSION["commande"]["prix"][$i]."'";             		  
				  	}
			  	 }
			  }
			  $sqlcommande = substr($sqlcommande, 0, strlen($sqlcommande)-1);
        $sqlcommande .= ");";  			  		  
			  mysql_query($sqlcommande) or die ("Erreur SQL > ".$sqlcommande."<br />".mysql_error()); 	
 
			  unset($_SESSION["commande"]);
 /* FINE STATISTICHE    */        
                }               
                else
                        echo '<br />Erreur répéter l\'opération.<div class="spa"></div>';
              
        }
?>
 
se metto un ; dopo la stringa con for funziona ma non calcola la quantità...però almeno non dà errore!

PHP:
for ($j = 0; $j < $_SESSION["commande"]["quantite"][$i]; $j++);
 
ciao
no penso che non dovrebbe essere quello, comunque se lo togli funziona? anche se quei cicli proprio non capisco a che servano, sei sicure di non averli modificati?
 
Se tolgo il ; funziona solo con 1 prodotto nell'ordine (quantità=1).
Se metto il ; funziona, ma anche se nell'ordine la quantità è > di 1 nella tabella inserisce comunque quantità=1
Se metto la riga come era prima e/o se tolgo il ;ecco l'errore (sempre lo stesso):

Erreur SQL > INSERT INTO tstat (idstat, datecommande, champtype, description, prix) VALUES( '', '2013-03-01', 'sand', 'Giorgio - Sandwiche - ',10.00''', '2013-03-01', 'sand', 'Giorgio - Sandwiche - ',10.00);
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 '''', '2013-03-01', 'sand', 'Giorgio - Sandwiche - ',10.00)' at line 1


Ma chi ha inventato il php?????
 
ciao
è quello che non capisco di quei cicli infatti da
INSERT INTO tstat (idstat, datecommande, champtype, description, prix) VALUES( '', '2013-03-01', 'sand', 'Giorgio - Sandwiche - ',10.00''', '2013-03-01', 'sand', 'Giorgio - Sandwiche - ',10.00);
ripetendo due volte i values
INSERT INTO tstat (idstat, datecommande, champtype, description, prix) VALUES( '', '2013-03-01', 'sand', 'Giorgio - Sandwiche - ',10.00''', '2013-03-01', 'sand', 'Giorgio - Sandwiche - ',10.00);
la query divrebbe risultare
INSERT INTO tstat (idstat, datecommande, champtype, description, prix) VALUES( '', '2013-03-01', 'sand', 'Giorgio - Sandwiche - ',10.00)
 
Ciao!
Ancora, ovviamente, non sono riuscito a risolvere l'enigma, in compenso ho notato (e sai che scoperta) che nella versione vecchia l'errore avviene ugualmente.
Quindi ti ho detto una bella c..., non è vero che funzionava!
Però il mio amico dice di sì. Quindi mi chiedevo: potrebbe essere un problema di aggiornamento PHP o roba del genere...
Sempre grazie mille!!!
 
ciao
si potrebbe, dipende da quanto è vecchio lo script.
tieni inoltre presente che mettere le mani di script di altri, a mio parere, è sempre una rogna.
 
ciao
prova a guardare nei vari script se al posto di $_POST['nome'] c'è $HTTP_POST_VARS ['nome'] lo script è vecchissimo e da buttare.
oggi cominciano ad essere deprecate anche le query al db tipo mysql_query e similari.

posso sbagliarmi (lo spero), ma la soluzione è rifare ex novo
 
Non voglio essere scortese, ma non c'è nessuna anima pia nel forum che potrebbe riscrivere lo script? Chiedo troppo forse? Non mi rendo bene conto...
 
forse mi sono perso qualche passaggio vista la lunghezza della discussione, ma immagino che se i prodotti siano piu di uno tu debba fare piu INSERT
in questo caso il primo pezzo di query dovrebbe andare all'interno del ciclo
PHP:
foreach ($cles as $i) {
    $sqlcommande = "INSERT INTO tstat (idstat, datecommande, champtype, description, prix) VALUES( ";
 
ciao criric
quello che non capisco è la concatenazione di quello che segue.
non so quello che succede nelle pagine precedenti, ma piu che la parte iniziale delle query (forse) va dentro il foreach anche la mysql_query, cioè inserisce e riparte con la nuova query.
però come detto bisogerebbe sapere come è il meccanismo del tutto e perchè nell'originale il programmatore abbia gfatto quell'ambaradan.
comunque da provare a mettere all'interno come dici tu (s.l.v. ossia se la và)
 
dunque ho fatto comne dice criric (grazie mille per l'interesse), ma non cambia nulla.
L'errore è sempre lo stesso:

Erreur SQL > INSERT INTO tstat (idstat, datecommande, champtype, description, prix) VALUES( '', '2013-03-06', 'shop', 'Focaccia - ',3.00''', '2013-03-06', 'shop', 'Focaccia - ',3.00);
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 '''', '2013-03-06', 'shop', 'Focaccia - ',3.00)' at line 1

Con 1 solo ordine funziona, se la quantità è 2 (o >) dà questo errore...
Perché non si separano? cioè dopo "near", nell'errore, non dovrebbe esserci una parentesi?
Cioè bla bla...server version for the right syntax to use near ....'')'('', '2013-03-06', 'shop', 'Focaccia - ',3.00)' at line 1

Forse l'errore è qui???
Domanda da un milione di dollari...
 

Discussioni simili