2013-03-13 6 views
0

i avait ce code de travail, et maintenant il ne délivre pas un total, il reste juste toujours à 0.PHP, Nombre de variables multiples au total

Je l'ai vérifié sur pour vous assurer que theres aucun demi manquant -colons ou quoi que ce soit.

Je suis conscient de son code très peu sûr, mais je voudrais juste le faire fonctionner pour l'instant!

<html> 
<head> 
<link rel="stylesheet" type="text/css" href="Style.css"> 
<link href='http://fonts.googleapis.com/css?family=Tauri' rel='stylesheet' type='text/css'> 
<link href='http://fonts.googleapis.com/css?family=Cantora+One' rel='stylesheet' type='text/css'> 
</head> 
<body> 
<div id="container"> 

<?php 
$firstchoice=$_POST["Cases"]; 
$secondchoice=$_POST["CPU"]; 
$thirdchoice=$_POST["Motherboard"]; 
$fourthchoice=$_POST["HDD"]; 
$fifthchoice=$_POST["PSU"]; 
$sixthchoice=$_POST["RAM"]; 
$seventhchoice=$_POST["GPU"]; 
?> 

<?php 



//prices 

$Casecom=12.27; 
$Antec300=31.99; 
$Coolermaster690 = 74.99; 
$CorsairObsidian = 148.05; 

$AMDAthlon450 = 32.00; 
$AMDA4 = 32.00; 
$AMDA10 = 95.12; 
$AMDFX8350 = 166.58; 
$IntelG530 = 36.99; 
$Inteli3 = 90.78; 
$Inteli5 = 148.14; 

$GigabyteGA78LMTUSB3 = 38.99; 
$ASUSSabertooth990FX = 135.50; 
$BiostarH61MU3H61 = 43.98; 
$AsusSABERTOOTHX79 = 263.90; 

$HitachiZ5K500 = 32.54; 
$WD3TB = 100.00; 
$OCZ128GB = 74.68; 
$OCZ240GB = 119.99; 

$CoolermasterGX550W = 57.99; 
$CasecomSilver500W = 99.99; 
$CorsairTX650W = 131.00; 

$Kingston2GBx1 = 11.00; 
$Kingston2GBx2 = 20.00; 
$KingstonHyperX = 14.99; 
$KingstonHyperX4GB = 26.54; 
$CrucialBallistix = 24.99; 
$CorsairValue4GB = 27.01; 
$CorsairXMS2GB = 34.57; 
$Kingston8GB = 40.00; 
$Corsair8GBVeng = 54.56; 
$GSkill8GB = 57.54; 
$CorsairXMS12GB = 67.43; 
$GSKill16GB = 88.94; 
$Corsair16GBVeng = 96.74; 

$XFXHD6450 = 34.59; 
$SapphireHD6570 = 53.67; 
$PowerColorHD6870 = 89.64; 
$XFXHD6870 = 124.65; 
$GigabyteHD7870 = 195.75; 
$KFAGT630 = 61.00; 
$EVGA650SC = 94.75; 
$Gigabyte650 = 133.56; 
$EVGAGTX660 = 215.78; 


if 
($firstchoice =="Casecom CM-262 Case"){ 
$total_price1 = $Casecom;} 
else if 
($firstchoice =="Antec 300 Case"){ 
$total_price1 = $Antec300;} 
else if 
($firstchoice =="Coolermaster 690 NVIDIA Edition"){ 
$total_price1 = $Coolermaster690;} 
else if 
($firstchoice =="Corsair Obsidian 900D Case"){ 
$total_price1 = $CorsairObsidian;} 


if 
($secondchoice =="AMD Athlon II X3 450 3.2Ghz 3-Core"){ 
$total_price2 = $AMDAthlon450;} 
else if 
($secondchoice =="AMD A4 3300 2.5GHz 2-Core"){ 
$total_price2 = $AMDA4;} 
else if 
($secondchoice =="AMD A10 5800K Black Edition 3.8GHz 4-Core"){ 
$total_price2 = $AMDA10;} 
else if 
($secondchoice =="AMD FX8350 4GHz 8-Core"){ 
$total_price2 = $AMDFX8350;} 
else if 
($secondchoice =="Intel Celeron G530 Single Core"){ 
$total_price2 = $IntelG530;} 
else if 
($secondchoice =="Intel Core i3 2120 Dual Core"){ 
$total_price2 = $Inteli3;} 
else if 
($secondchoice =="Intel Core i5 2320 Quad Core"){ 
$total_price2 = $Inteli5;} 

if 
($thirdchoice =="Gigabyte GA-78LMT-USB3 760G Socket AM3+ VGA DVI HDMI 7.1 Channel Audio mATX"){ 
$total_price3 = $GigabyteGA78LMTUSB3;} 
else if 
($thirdchoice =="ASUS Sabertooth 990FX R2.0 Socket AM3+ 8 Channel Audio ATX Motherboard"){ 
$total_price3 = $ASUSSabertooth990FX;} 
else if 
($thirdchoice =="Biostar H61MU3 H61 Socket 1155 6 Channel HD Audio mATX Motherboard"){ 
$total_price3 = $BiostarH61MU3H61;} 
else if 
($thirdchoice =="Asus SABERTOOTH X79 Socket 2011 8 Channel Audio ATX Motherboard"){ 
$total_price3 = $AsusSABERTOOTHX79;} 

if 
($fourthchoice =="Hitachi 250GB Travelstar Z5K500 Internal Hard Drive"){ 
$total_price4 = $HitachiZ5K500;} 
else if 
($fourthchoice =="WD 3TB Green Desktop Drive"){ 
$total_price4 = $WD3TB;} 
else if 
($fourthchoice =="OCZ 128GB Agility 4 SSD"){ 
$total_price4 = $OCZ128GB;} 
else if 
($fourthchoice =="OCZ 240GB Agility 4 SSD"){ 
$total_price4 = $OCZ240GB;} 

if 
($fifthchoice =="Coolermaster GX 550W PSU"){ 
$total_price5 = $CoolermasterGX550W;} 
else if 
($fifthchoice =="Casecom Silver 500W PSU - With 12cm Red LED Fan"){ 
$total_price5 = $CasecomSilver500W;} 
else if 
($fifthchoice =="Corsair TX 650W PSU - 80plus Bronze Certified"){ 
$total_price5 = $CorsairTX650W;} 

if 
($sixthchoice =="Kingston 2GB DDR3 1600MHz Value Memory"){ 
$total_price6 = $Kingston2GBx1;} 
else if 
($sixthchoice =="Kingston 2x 2GB(4GB) DDR3 1600MHz Value Memory"){ 
$total_price6 = $Kingston2GBx2;} 
else if 
($sixthchoice =="Kingston 2GB DDR3 1333MHz HyperX Black Series"){ 
$total_price6 = $Kingston2GBx2;} 
else if 
($sixthchoice =="Kingston 4GB DDR3 1600MHz HyperX Black Series"){ 
$total_price6 = $Kingston4GB;} 
else if 
($sixthchoice =="Crucial 2GB DDR2 800MHz Ballistix Sport Memory"){ 
$total_price6 = $CrucialBallistix;} 
else if 
($sixthchoice =="Corsair Value 4GB (2x2GB) DDR3 1333MHz Memory"){ 
$total_price6 = $CorsairValue4GB;} 
else if 
($sixthchoice =="Corsair 2GB DDR2 800MHz XMS2 Memory"){ 
$total_price6 = $CorsairXMS2GB;} 
else if 
($sixthchoice =="Kingston 8GB DDR3 1600MHz HyperX Genesis Memory"){ 
$total_price6 = $Kingston8GB;} 
else if 
($sixthchoice =="Corsair 8GB (2X4GB) DDR3 1600Mhz RED Vengeance Memory Kit CL8 1.5V"){ 
$total_price6 = $Corsair8GBVeng;} 
else if 
($sixthchoice =="G.Skill 8GB DDR3 1600mhz Sniper Memory"){ 
$total_price6 = $GSkill8GB;} 
else if 
($sixthchoice =="Corsair 12GB DDR3 1600Mhz XMS Memory"){ 
$total_price6 = $CorsairXMS12GB;} 
else if 
($sixthchoice =="G.Skill 16GB DDR3 1600MHz RipjawsZ X79 Memory"){ 
$total_price6 = $GSKill16GB;} 
else if 
($sixthchoice =="Corsair 16GB 1600MHz Vengeance Blue Memory"){ 
$total_price6 = $Corsair16GBVeng;} 

if 
($seventhchoice =="XFX HD 6450 Core 2GB DDR3 VGA DVI HDMI PCI-E Graphics Card"){ 
$total_price7 = $XFXHD6450;} 
else if 
($seventhchoice =="Sapphire HD 6570 2GB DDR3 DVI VGA HDMI PCI-E Graphics Card"){ 
$total_price7 = $SapphireHD6570;} 
else if 
($seventhchoice =="XFX HD 6870 900MHz 1GB GDDR5 Dual DVI Dual Mini DisplayPort HDMI PCI-E Graphics"){$total_price7 = $XFXHD6870;} 
else if 
($seventhchoice =="Gigabyte HD 7870 OC 2048MB GDDR5 DVI HDMI Dual Mini DisplayPort PCI-E Graphics"){$total_price7 = $GigabyteHD7870;} 
else if 
($seventhchoice =="KFA2 GT 630 2GB DDR3 VGA DVI HDMI PCI-E Graphics Card"){$total_price7 = $KFAGT630;} 
else if 
($seventhchoice =="EVGA GTX 650 SuperClocked 1GB GDDR5 Dual DVI Mini HDMI PCI-E Graphics Card"){$total_price7 = $EVGA650SC;} 
else if 
($seventhchoice =="Gigabyte GTX 650 Ti 2GB GDDR5 5400MHz Dual DVI 1x HDMI PCI-E Graphics Card"){$total_price7 = $Gigabyte650;} 
else if 
($seventhchoice =="EVGA GTX 660 Ti 2048MB GDDR5 Dual DVI HDMI DisplayPort PCI-E Graphics Card"){$total_price7 = $EVGAGTX660;} 

else 
?> 

<div id="Subtitle"> 
<?php 
echo "Order Summary" 
?> 
</div> 
<div id="orderSummary"> 
<div id="CaseItem"> 
<h3>Case:</h3> 
<?php 
echo $firstchoice; 
?> 
</div> 
<div id="CPUItem"> 
<h3>CPU:</h3> 
<?php 
echo $secondchoice; 
?> 
</div> 
<div id="MotherboardItem"> 
<h3>Motherboard:</h3> 
<?php 
echo $thirdchoice; 
?> 
</div> 
<div id="HDDItem"> 
<h3>Hard Disk Drive</h3> 
<?php 
echo $fourthchoice; 
?> 
</div> 
<div id="PowerSupplyItem"> 
<h3>Power Supply</h3> 
<?php 
echo $fifthchoice; 
?> 
</div> 
<div id="RAMItem"> 
<h3>Memory (RAM)</h3> 
<?php 
echo $sixthchoice; 
?> 
</div> 
<div id="GPUItem"> 
<h3>Graphics Card: </h3> 
<?php 
echo $seventhchoice; 
?> 
</div> 
<div id="TotalCost"> 
<?php 
echo nl2br (" \r\n"); 
$overall_price = $total_price1 + $total_price2 + $total_price3 + $total_price4 + $total_price5 + $total_price6 + $total_price7; 
echo "Total Cost: " .$overall_price; 
?> 
</div> 
</div> 

</div> 
<body> 
<html> 
+0

Ce n'est pas la sécurité qui est le plus gros problème ici, il est tout simplement pas maintenable. Honnêtement, ce code est un cauchemar –

+0

Avez-vous considéré que POST est vide ou n'a aucun choix dans les variables? Faites un var_dump ($ _ POST) et vérifiez ce qu'il y a dedans. – sikander

+0

vous devriez apprendre à utiliser des tableaux. – didierc

Répondre

0

Presque certainement, vos _POST variables ne correspondent pas aux options dans les if/else blocs.

Je dis cela parce que j'exécuter votre code, ce qui ne le remplacement suivant:

$firstchoice="Casecom CM-262 Case"; //$_POST["Cases"]; 
$secondchoice="AMD Athlon II X3 450 3.2Ghz 3-Core"; //$_POST["CPU"]; 
$thirdchoice="Gigabyte GA-78LMT-USB3 760G Socket AM3+ VGA DVI HDMI 7.1 Channel Audio mATX"; //$_POST["Motherboard"]; 
$fourthchoice="Hitachi 250GB Travelstar Z5K500 Internal Hard Drive"; //$_POST["HDD"]; 
$fifthchoice="Coolermaster GX 550W PSU"; //$_POST["PSU"]; 
$sixthchoice="Kingston 2GB DDR3 1600MHz Value Memory"; //$_POST["RAM"]; 
$seventhchoice="XFX HD 6450 Core 2GB DDR3 VGA DVI HDMI PCI-E Graphics Card"; //$_POST["GPU"]; 

(... cette modification a été apportée à l'emplacement évident très près du haut du code dans votre question.)

Avec les chaînes codées en dur pour correspondre à l'une des options dans chacune des if/else boucles correspondantes dans votre code, le résultat est:

total Coût: 219,38

Ceci est une forte preuve que votre code donne le résultat souhaité, mais que les variables $ _POST ne sont pas réellement comme vous l'attendez.

Vous pouvez ajouter un print_r($_POST); près du sommet pour voir ce qui est en réalité à venir dans.