Hej vi er ved at lave en hjemmeside, men siden vises ikke rigtigt, hvad er der galt?
og hvordan laver jeg så tingene får en størrelse, der kan opdateres?
siden er www.xxxxx.dk
koden der styrer det hele er denne
<?
define(SECURE_URL, "http:///mydb1.surftown.dk/xxxxx.dk/admin/");
define(IMAGE_URL, "http:///mydb1.surftown.dk/xxxxx.dk/images/");
define(SHIPPING_COST, "42,50");
define(COMPANY_NAME, "5xX biXen");
define(CREDIT_AUTH_URL, "finishorder.php");
define(COMPANY_EMAIL, "bixen@xxxxx.dk");
$conn = mysql_connect("mydb1.surftown.dk", "XXX", "XXX")
or die(mysql_error());
mysql_select_db("michell_varelager",$conn) or die(mysql_error());
function errortrap($result) {
if(DB::isError($result)) {
?><h3>Der opstod en fejl!</h3><?
die($result->getMessage());
}
} //slut på errortrap
function alter_cart($cat, $items, $item, $action) {
global $dbconn;
$sql = "select * from inventory where id = '$item' AND category = '$cat'";
$result = $dbconn->query($sql);
errortrap($result);
if($result->numRows() > 0) {
switch($action) {
case("add"):
if(!isset($items[$cat][$item])) {
$items[$cat][$item] = 0;
}
$items[$cat][$item]++;
break;
case("remove"):
if(isset($items[$cat][$item])) {
$items[$cat][$item]--;
}
if($items[$cat][$item] < 1) {
unset($items[$cat][$item]);
}
break;
default:
break;
}
}
return $items;
} //slut på alter_cart
function full_item($item, $items) {
global $dbconn;
$sql = "select * from inventory where id = $item";
$result = $dbconn->query($sql);
errortrap($result);
$result->fetchinto($r);
?>
<table border=1 cellpadding=5 cellspacing=0>
<tr><td class=tablehead><?=$r["name"]?></td></tr>
<tr><td><?=$r["name"]?><?=$r["description"]?>
<b>Pris</b>: <?=$r["price"]?>
<p>
<?
if($r["picture"] != "") {
?><div align="center"><img src="<? echo IMAGE_URL . $r["picture"]?>"></div><?
}
if($r["qty"] > 1) {
?>
<p><div align=center><a href="<?=SECURE_URL?>cart.php?cat=<?=$r["category"]?>&item=<?=$item?>&itemview=<?=$item?>&action=add"><img src="<?=IMAGE_URL?>tilfoej.gif" border=0></a>
<?
} else {
?>
<p>Beklager - der er ikke flere på lager!</p>
<?
}
?>
<a href="<?=SECURE_URL?>cart.php">Retur til oversigt over varer i denne kategori</a></div></td></tr>
</table>
<?
} //slut på full_item
function build_menu ($ref, $table) {
global $dbconn;
$sql = "select * from $table order by id";
$result = $dbconn->query($sql);
errortrap($result);
if($result->numRows() > 0) {
$x = 0;
while($result->fetchInto($r)){
if($x == 0) {
echo '<option value="' . $r["id"] . '" selected>' . $r[$ref] . '</option>';
$x++;
} else {
echo '<option value="' . $r["id"] . '">' . $r[$ref] . '</option>';
}
}
} else {
echo '<option value="">Der er ikke defineret nogen katagorier!</option>';
}
} //slut på build_menu
function head() {
?>
<html>
<head>
<style type=text/css>
h1, h2, h3, p, td {font-family: verdana, sans-serif; }
.tablehead {font-size: 12pt; color: #FFFFFF; background-color: #000099; }
.required {font-weight: bold; color: red; }
.smalli {font-size: 8pt; font-style: italic;}
</style>
</head>
<body bgcolor="#FFFFFF">
<div align=center>
<table width="74%" border="0" cellspacing="0" cellpadding="0" height="128" bgcolor="#FFFFFF">
</table>
<?
}
function calculate_total($items) {
global $dbconn;
$shipping = SHIPPING_COST;
$total = 0;
foreach($items as $key => $val) {
foreach($items[$key] as $key2 => $val2) {
$sql = "select * from inventory where id = '$key2'";
$result = $dbconn->query($sql);
errortrap($result);
$result->fetchinto($r);
$total+= ($r["price"] * $val2);
}
}
if($total != 0) {
$total = $total + $shipping;
}
return $total;
} //slut på calculate_total
function display_cart($items) {
global $dbconn;
global $items, $status;
$shipping = SHIPPING_COST;
$count = 0;
?>
<table border=1 cellpadding=5 cellspacing=0>
<tr><td class=tablehead>Produktnavn</td><td class=tablehead>Antal</td><td class=tablehead>Á pris</td><td class=tablehead> </td></tr>
<?
foreach($items as $cat => $val) {
foreach($items[$cat] as $item => $qty) {
$sql = "select * from inventory where id = '$item'";
$result = $dbconn->query($sql);
errortrap($result);
$result->fetchinto($r);
?>
<tr><td><?=$r["name"]?></td><td><?=$qty?></td><td><?=$r["price"]?></td>
<?
if($status == "checkout") {
echo "<td> </td>";
} else {
?>
<td><a href="<?=SECURE_URL?>cart.php?cat=<?=$r["category"]?>&item=<?=$r["id"]?>&action=remove">
<img src="<?=IMAGE_URL?>fjern.gif" border=0></a></td>
<?
}
?>
</tr>
<?
$count++;
}
}
if($count == 0) {
$items= array();
?>
<tr><td colspan=4><h3>Din indkøbsvogn er tom!</h3></td><tr>
<?
}
$total = calculate_total($items);
?>
<tr><td colspan=3>Håndtering og forsendelse</td><td><?=$shipping?></td></tr>
<tr><td class=smalli>
<?
if($status != "checkout") {
if($count > 0) {
?>Klik <a href=<?=SECURE_URL?>cart.php?modify=bulk">HER</a> for at ændre på mængden ved storkøb i din indkøbsvogn.<?
}
}
?>
</td><td colspan="2" align="right">Total:</td><td>
<?
printf("%.2f", $total);
?></td></tr></table><?
}//slut på display_cart
function cart2form($items) {
foreach($items as $cat => $val) {
foreach($val as $item => $qty) {
?>
<input type="hidden" name="cart[<?=$item; ?>]" value="<?=$qty; ?>">
<?
}
}
}//slut på cart2form
function display_items($cat, $items) {
global $dbconn;
$sql = "select * from inventory where category = '$cat'";
$result = $dbconn->query($sql);
errortrap($result);
if($result->numRows() > 0) {
?>
<h2>Varer i denne kategori:</h2>
<table border=1 cellpadding=5 cellspacing=0>
<tr><td class=tablehead>Produktnavn <div class=smalli>klik på navnet for detaljer</div></td><td class=tablehead>Pris</td><td class=tablehead> </td></tr>
<?
while($result->fetchinto($r)) {
?>
<tr><td><a href="<?=SECURE_URL?>cart.php?itemview=<?=$r["id"]?>"><?=$r["name"]?></a></td>
<td><?=$r["price"]?></td>
<td>
<?
if($r["qty"] > 1) {
?>
<a href="<?=SECURE_URL?>cart.php?cat=<?=$r["category"]?>&item=<?=$r["id"]?>&action=add"><img src="<?=IMAGE_URL?>tilfoj.gif" border=0></a>
<?
} else {
?>
Ingen på lager!
<?
}
?>
</td></tr>
<?
}
?>
</table>
<?
} else {
echo "<h3>Vælg en kategori ovenfor</h3>";
}
} //slut på display_items
function edit_cart($items) {
global $dbconn;
?>
<form action=cart.php method=post>
<table border=1 cellpadding=5 cellspacing=0>
<tr><td class=tablehead>Produktnavn</td><td class=tablehead>Á pris</td><td class=tablehead>Antal</td></tr>
<?
foreach($items as $cat => $val) {
foreach($items[$cat] as $item => $qty) {
$sql = "select * from inventory where id = '$item'";
$result = $dbconn->query($sql);
errortrap($result);
$result->fetchinto($r);
?>
<tr><td><?=$r["name"]?></td><td><?=$r["price"]?></td>
<td>
<input type="text" name="items_in[<?=$cat?>][<?=$item?>]" value="<?=$qty?>" size="3">
</td></tr>
<?
}
}
?>
</table>
<input type="submit" name="update_cart" value="Opdater indkøbsvogn">
</form>
<?
} //slut på edit_cart
function select_cat() {
?>
<form action=cart.php method=post>
<p>Vælg en varekategori: <select name="category_choice_in">
<? build_menu("name","category"); ?>
</select>
<input type="submit" name="submit" value="Send">
</form>
<?
} //slut på select_cat
?>
og denne her vises:
<?
require_once("include/cart_inc.php");
session_start();
session_register("items");
session_register("category_choice");
session_register("total");
if(!isset($items)) {
$items = array();
}
if(!isset($category_choice)) {
$category_choice=1;
}
/*************** MAIN ***************/
head();
$dbconn = mysql_connect;
select_cat();
$status = "shopping";
?>
<table width="58%" border="1" cellspacing="10" cellpadding="10" height="371" bordercolor="#0000FF" bgcolor="#999999">
<tr align="left" valign="top">
<td bgcolor="#CCCCCC" bordercolor="#0000FF">
<table border="0" cellpadding="10"><tr><td valign=top>
<?
if(isset($category_choice_in)) {
$category_choice = $category_choice_in;
}
if(isset($update_cart)) {
foreach($items_in as $cat => $val) {
foreach($items_in[$cat] as $id => $qty) {
if($qty < 1) {
unset($items_in[$cat][$id]);
}
}
}
$items = $items_in;
}
if(isset($itemview)) {
full_item($itemview, $items);
} else {
display_items($category_choice,$items);
}
if(isset($action)) {
$items = alter_cart($cat, $items, $item, $action);
}
?>
</td><td valign=top>
<h3>Din indkøbsvogn:</h3>
<?
if(isset($modify)) {
edit_cart($items);
} else {
display_cart($items);
}
?>
<p>
<?
if(sizeof($items) > 0) {
$total = calculate_total($items);
//print_r($items);
?>
<p>Vil du <a href="<?=SECURE_URL?>checkout.php"><b>checke ud</b></a>?
<?
}
?>
</td></tr></table>
</td>
</tr>
</table>
</div>
</body>
</html>
chechout
<?
require_once("include/cart_inc.php");
session_start();
head();
$dbconn = mysql_connect;
$response = "1";
//$response = "2"; //kreditkort afvist
//$response = "3"; //generel fejl
if(sizeof($items) == 0) {
?>
<h3>Der er ingen varer i din vogn! Klik på din browsers "Tilbage"-knap, og læg nogle varer i din vogn!</h3>
<?
} else {
?>
<h2>Her er en oversigt over de varer, du bestiller:</h2>
<?
$status = "checkout";
display_cart($items);
?>
<p>Indtast venligst følgende information før du fortsætter:<p>
<FORM METHOD=POST ACTION="<?=CREDIT_AUTH_URL?>">
<INPUT TYPE=HIDDEN NAME="Amount" VALUE="<?=$total?>">
<INPUT TYPE=HIDDEN NAME="x_Description" VALUE="Order From <?=COMPANY_NAME?>">
<INPUT TYPE=HIDDEN NAME="x_Invoice_Num" VALUE="<?=time()?>">
<INPUT TYPE=HIDDEN NAME="x_response_code" VALUE="<?=$response?>">
<?cart2form($items);?>
<table border="1" cellspacing="1" cellpadding="5">
<tr>
<td colspan="2" class="tablehead"><b>FAKTURERINGS ADRESSE</b>:</td>
</tr>
<tr>
<td>Kreditkortnr.<span class="required">*</span></td>
<td>
<input type="text" name="x_card_num">
</td>
</tr>
<tr>
<td>Udløbsdato<span class="required">*
(MMÅÅ - for eksempel 0403 for April 2003)</span></td>
<td>
<input type="text" name="x_exp_date" maxlength="4" size="4">
</td>
</tr>
<tr>
<td>Fornavn<span class="required">*</span></td>
<td>
<input type="text" name="x_first_name">
</td>
</tr>
<tr>
<td>Mellemnavn eller initial</td>
<td>
<input type="text" name="x_mi">
</td>
</tr>
<tr>
<td>Efternavn<span class="required">*</span></td>
<td>
<input type="text" name="x_last_name">
</td>
</tr>
<tr>
<td>Adresse 1<span class="required">*</span></td>
<td>
<input type="text" name="x_address">
</td>
</tr>
<tr>
<td>Adresse 2:</td>
<td>
<input type="text" name="x_address_2">
</td>
</tr>
<tr>
<td>By<span class="required">*</span></td>
<td>
<input type="text" name="x_city">
</td>
</tr>
<tr>
<td>Postnr<span class="required">*</span></td>
<td>
<input type="text" name="x_zip" size="10" maxlength="10">
</td>
</tr>
<tr>
<td>Land<span class="required">*</span></td>
<td>
<select name=x_country>
<option> Danmark
<option> Sverige
<option selected> Norge
</select>
</td>
</tr>
<tr>
<td>Tlfnr. i dagtimerne</td>
<td>
<input type="text" name="x_phone">
</td>
</tr>
<tr>
<td>Email<span class="required">*</span></td>
<td>
<input type="text" name="x_email">
</td>
</tr>
<tr>
<td>Hvis modtageradresse er den samme som faktureringsadresse.. </td>
<td>
<input type="checkbox" name="shiptobilling" value="true">
<font size="-2"> (sæt da kryds i denne boks)</font></td>
</tr>
<tr>
<td colspan="2" class="tablehead">
<p><b>Modtageradresse</b>
(Udfyld disse linjer, hvis din modtageradresse er forskellig fra faktureringsadressen):</p>
</td>
</tr>
<tr>
<td>Adresselinje 1:</td>
<td>
<input type="text" name="x_ship_to_address">
</td>
</tr>
<tr>
<td>Adresselinje 2:</td>
<td>
<input type="text" name="x_ship_to_address2">
</td>
</tr>
<tr>
<td>By</td>
<td>
<input type="text" name="x_ship_to_city">
</td>
</tr>
<tr>
<td>Landekode</td>
<td>
<input type="text" name="x_ship_to_state" size="2" maxlength="2">
</td>
</tr>
<tr>
<td>Postnr</td>
<td>
<input type="text" name="x_ship_to_zip" size="10" maxlength="10">
</td>
</tr>
<tr>
<td>Land</td>
<td>
<select name=x_ship_to_country>
<option> Norge
<option> Sverige
<option selected> Danmark
</select>
</td>
</tr>
</table>
<p>
<INPUT TYPE=SUBMIT VALUE="Afsend ordre">
</p>
</FORM>
<?
session_unset();
session_destroy();
}
?>
finish order
<?
require_once("include/cart_inc.php");
head();
$dbconn = mysql_connect;
switch($x_response_code) {
case("1"):
if(!isset($shiptobilling)) {
$shiptobilling = "false";
}
$id = $dbconn->nextID('customers',true);
$sql = "insert into customers values ('$id', '$x_first_name', '$x_mi', '$x_last_name', '$x_address', '$x_address_2', '$x_city', '$x_state', '$x_zip', '$x_country', '$shiptobilling', '$x_ship_to_address', '$x_ship_to_address2', '$x_ship_to_city', '$x_ship_to_state', '$x_ship_to_zip', '$x_ship_to_country', '$x_phone', '$x_email')";
$result = $dbconn->query($sql);
errortrap($result);
$id2 = $dbconn->nextID('orders',true);
$sql = "insert into orders values ('$id2', '$id', 'open', NULL)";
$result = $dbconn->query($sql);
errortrap($result);
foreach($cart as $code => $qty) {
$id3 = $dbconn->nextID('order_details',true);
$sql = "insert into order_details values ('$id3', '$id2', '$code', '$qty')";
$result = $dbconn->query($sql);
errortrap($result);
$sql2 = "update inventory set qty = qty-'$qty' where id = '$code'";
$result2 = $dbconn->query($sql2);
errortrap($result2);
}
$mail = "Tak for din ordre fra " . COMPANY_NAME . "!\\n";
$mail .= "Vi har modtaget din ordre og giver besked, når ordren bliver afsendt.";
// mail($x_email, "Din ordre fra " . COMPANY_NAME, $mail, "From: " . COMPANY_NAME . " <" . COMPANY_EMAIL . ">");
?>
<h2>Mange tak!</h2>
<p>Din bestilling er accepteret. Du modtager en kvittering på e-mail i løbet af et par minutter.
<h3>UNDLAD AT OPDATERE DENNE SIDE, DA DU ELLERS FEJLAGTIGT KAN BLIVE FAKTURERET TO GANGE!</h3>
<?
break;
case("2"):
?>
<h3>Dit kreditkort blev afvist</h3>
<p>Grunden var: <?=$x_response_reason_text?>
<?
break;
case("3"):
?>
<h3>Der opstod en fejl under behandlingen af din bestilling</h3>
<p>Grunden var: <?=$x_response_reason_text?>
<?
break;
default:
?>
<h3>Der opstod en fejl under behandlingen af din bestilling</h3>
<?
break;
} //slut på switch
?>
<hr>
</body>
</html>
[Redigeret d. 01/04-04 10:52:38 af Anette]