da_mike
Grünschnabel
Sodala ich hab ein riesen Problem, und ich komm durch googlen und suchen in einigen Foren nicht wirklich weiter.
Ich versuch eine Preisberechnung zu gestallten wo durch 2 Drop down felder die anzahl und die optionen ein preis berechnet werden soll. Das Problem an der ganzen Sache ist das ich mich noch nicht wirklich sehr gut mit PHP auskenne und irgendwo im folgenden Script einen Denkfehler habe.
Addieren krieg ich hin aber Multiplizieren unter PHP leider noch nicht.
Vielleicht habt wisst ihr eine Lösung für mein Problem.
Ich versuch eine Preisberechnung zu gestallten wo durch 2 Drop down felder die anzahl und die optionen ein preis berechnet werden soll. Das Problem an der ganzen Sache ist das ich mich noch nicht wirklich sehr gut mit PHP auskenne und irgendwo im folgenden Script einen Denkfehler habe.
Addieren krieg ich hin aber Multiplizieren unter PHP leider noch nicht.
Vielleicht habt wisst ihr eine Lösung für mein Problem.
PHP:
<form action="preis.php" method="post" target="_blank">
<div align="center">
<table width="500" border="0" cellspacing="0" >
<tr>
<td width="496" colspan="2"><b>Grundpreis x Anzahl</b></td>
</tr>
<tr>
<td width="496" colspan="2"> </td>
</tr>
<tr>
<td width="166">Anzahl (max5)</td>
<td width="330">
<select name="anzahl">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">3</option>
<option value="5">3</option>
</select> </td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td width="166">Optionen</td>
<td width="330"> <select name="optionen">
<option value="opt1">option 1</option>
<option value="opt2">option 2</option>
<option value="opt3">option 3</option>
<option value="opt3">option 4</option>
<option value="opt3">option 5</option>
<option value="opt3">option 6</option>
<option value="opt3">option 7</option>
<option value="opt3">option 8</option>
</select>
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"> <b>Extra nur Addiert</b></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"> Extra1 <input type="checkbox" name="x1" value="ja" /></td>
</tr>
<tr>
<td colspan="2"> Extra2 <input type="checkbox" name="x2" value="ja" /></td>
</tr>
<tr>
<td colspan="2"> Extra3 <input type="checkbox" name="x3" value="ja" /></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"> <b>Extra von Anzahl Abhängig</b></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"> Extra4 <input type="checkbox" name="x4" value="ja" /> dieser
preis soll von der angegebenen Anzahl abhängig sein</td>
</tr>
<tr>
<td colspan="2"> Extra5 <input type="checkbox" name="x5" value="ja" /> dieser
preis soll von der angegebenen Anzahl abhängig sein</td>
</tr>
<tr>
<td colspan="2"> Extra6 <input type="checkbox" name="x6" value="ja" /> dieser
preis soll von der angegebenen Anzahl abhängig sein</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"> <br />
<input type="submit" value=" Berechnen " name="submit" />
<br />
</td>
</tr>
</table>
</div>
</form>
<?php
// Ausgangswert Preisberechnung
$preis = 0;
// Variablen Anzahl
if ($HTTP_POST_VARS[anzahl] == "1") { = 1; }
if ($HTTP_POST_VARS[anzahl] == "2") { = 2; }
if ($HTTP_POST_VARS[anzahl] == "3") { = 3; }
if ($HTTP_POST_VARS[anzahl] == "4") { = 4; }
if ($HTTP_POST_VARS[anzahl] == "5") { = 5; }
// Optionen
if ($HTTP_POST_VARS[optionen] == "opt1") { = 100; }
if ($HTTP_POST_VARS[optionen] == "opt2") { = 200; }
if ($HTTP_POST_VARS[optionen] == "opt3") { = 300; }
if ($HTTP_POST_VARS[optionen] == "opt4") { = 400; }
if ($HTTP_POST_VARS[optionen] == "opt5") { = 500; }
if ($HTTP_POST_VARS[optionen] == "opt6") { = 600; }
if ($HTTP_POST_VARS[optionen] == "opt7") { = 700; }
if ($HTTP_POST_VARS[optionen] == "opt8") { = 800; }
// Grunpreis x Anzahl
// OPT 1
if ($HTTP_POST_VARS[anzahl] == "1" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[op1] * 1);
}
if ($HTTP_POST_VARS[anzahl] == "2" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[op1] * 2);
}
if ($HTTP_POST_VARS[anzahl] == "3" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[op1] * 3);
}
if ($HTTP_POST_VARS[anzahl] == "4" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[op1] * 4);
}
if ($HTTP_POST_VARS[anzahl] == "5" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[opt1] * 5);
}
// Opt2
if ($HTTP_POST_VARS[anzahl] == "1" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[opt2] * 1);
}
if ($HTTP_POST_VARS[anzahl] == "2" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[opt2] * 2);
}
if ($HTTP_POST_VARS[anzahl] == "3" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[opt2] * 3);
}
if ($HTTP_POST_VARS[anzahl] == "4" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[opt2] * 4);
}
if ($HTTP_POST_VARS[anzahl] == "5" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[opt2] * 5);
}
// opt 3
if ($HTTP_POST_VARS[anzahl] == "1" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[opt3] * 1);
}
if ($HTTP_POST_VARS[anzahl] == "2" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[opt3] * 2);
}
if ($HTTP_POST_VARS[anzahl] == "3" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[opt3] * 3);
}
if ($HTTP_POST_VARS[anzahl] == "4" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[opt3] * 4);
}
if ($HTTP_POST_VARS[anzahl] == "5" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[opt3] * 5);
}
// opt 3
if ($HTTP_POST_VARS[anzahl] == "1" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[opt4] * 1);
}
if ($HTTP_POST_VARS[anzahl] == "2" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[opt4] * 2);
}
if ($HTTP_POST_VARS[anzahl] == "3" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[opt4] * 3);
}
if ($HTTP_POST_VARS[anzahl] == "4" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[opt4] * 4);
}
if ($HTTP_POST_VARS[anzahl] == "5" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[opt4] * 5);
}
// opt 5
if ($HTTP_POST_VARS[anzahl] == "1" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[opt5] * 1);
}
if ($HTTP_POST_VARS[anzahl] == "2" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[opt5] * 2);
}
if ($HTTP_POST_VARS[anzahl] == "3" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[opt5] * 3);
}
if ($HTTP_POST_VARS[anzahl] == "4" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[opt5] * 4);
}
if ($HTTP_POST_VARS[anzahl] == "5" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[opt5] * 5);
}
// Extra Nur Addiert
if ($HTTP_POST_VARS[x1] == "ja") { $preis += 25; }
if ($HTTP_POST_VARS[x2] == "ja") { $preis += 50; }
if ($HTTP_POST_VARS[x3] == "ja") { $preis += 75; }
// Extras die von der Anzahl abhängig sind
if ($HTTP_POST_VARS[x4] == "ja" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[anzahl] * 15);
}
if ($HTTP_POST_VARS[x5] == "ja" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[anzahl] * 30);
}
if ($HTTP_POST_VARS[x6] == "ja" || $HTTP_POST_VARS[anzahl] != "") {
$preis += ($HTTP_POST_VARS[anzahl] * 45);
}
echo "<html><font face=\"verdana, helvetica\" size=-1>";
echo "Der Preis beträgt<b>$preis,- EUR</b>";
?>
Zuletzt bearbeitet: