<?php
include_once "path/db.php";
include_once "path/functions.php";
[b]if ($_REQUEST['command']=='add' && $_REQUEST['productid']>0) {
$pid=$_REQUEST['productid'];
addtocart($pid, 1);
header("location:shoppingcart.php");
exit();
}
$priceid=$REQUEST['priceid'];[/b]
?>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;">
<title>Photojournalist and webdesigner Sofus Comer - Thy, Denmark</title>
<link href="../stylesheet.css" rel="stylesheet" type="text/css" media="only screen and (min-width:961px)" />
<!-- iphone -->
<link href="../iphone.css" rel="stylesheet" type="text/css" media="only screen and (max-width:960px)">
[b]<script language="javascript">
function addtocart(pid,priceid){
document.form1.productid.value=pid;
document.form1.priceid.value=priceid;
document.form1.command.value='add';
document.form1.submit();
}
</script>[/b]
</head>
<body>
<div class="div_master">
<div class="titlediv">Photojournalist Sofus Comer</div>
<?php
include_once "../menu_includes/menu_main.php";
?>
<div class="descript"></div>
<div class="div_main">
<div class="page_right">
<div class="portfolio_view_title">Ordering Prints</div>
<div class="photostreamExif"></div>
<div class="clear"></div>
</div>
<div class="page_master">
<form name="form1">
<input type="hidden" name="productid" />
<input type="hidden" name="command" />
<table border="0" cellpadding="2px" width="auto">
<?php
$result=mysql_query("select * from sometable WHERE ids = 630 ORDER BY ids DESC LIMIT 100");
while ($row=mysql_fetch_array($result)) {
?>
<tr>
<td><img src="../path_to_images/somemore_<?php echo $row['idf']?>.jpg" class="img_border_white"/></td>
<td><b>Image ID: <?php echo $row['ids'];?>_<?php echo $row['idf'];?>_<?php echo $row['image']?></b>
<br />
<?php echo $row['caption']?>
<br />
Price:<big style="color:green">
[b] <select name="priceid" id="priceid">
<option value="1">A4 (With 1,2cm white border)</option>
<option value="2">A3 (With 1,2cm white border)</option>
<option value="3">A3+ (With 1,2cm white border)</option>
<option value="4">A2 (With 1,2cm white border)</option>
<option value="5">A2 (Borderless)</option>
</select>[/b]
</form>
</big>
<br /><br />
<input type="button" value="Add to cart" onclick="addtocart(<?php echo $row['idf']?>)" />
</td>
</tr>
<tr><td colspan="2"><hr size="1" /></td>
<?php } ?>
</table>
</div>
</div>
</div>
</div>
</body>
</html>
<?php
function get_product_name($pid){
$result=mysql_query("select idf,image,ids from tablename where idf=$pid");
$row=mysql_fetch_array($result);
return $row['ids']."_".$row['idf']."_".$row['image'];
}
[b]function get_price($priceid){
$result=mysql_query("select price from printpricesandoptions where id=$priceid");
$row=mysql_fetch_array($result);
return $row['price'];
}[/b]
function remove_product($pid){
$pid=intval($pid);
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){
if($pid==$_SESSION['cart'][$i]['productid']){
unset($_SESSION['cart'][$i]);
break;
}
}
$_SESSION['cart']=array_values($_SESSION['cart']);
}
function get_order_total(){
$max=count($_SESSION['cart']);
$sum=0;
for($i=0;$i<$max;$i++){
$pid=$_SESSION['cart'][$i]['productid'];
$q=$_SESSION['cart'][$i]['qty'];
$price=get_price($priceid);
$sum+=$price*$q;
}
return $sum;
}
function addtocart($pid,$q){
if($pid<1 or $q<1) return;
if(is_array($_SESSION['cart'])){
if(product_exists($pid)) return;
$max=count($_SESSION['cart']);
$_SESSION['cart'][$max]['productid']=$pid;
$_SESSION['cart'][$max]['priceid']=$price;
$_SESSION['cart'][$max]['qty']=$q;
}
else{
$_SESSION['cart']=array();
$_SESSION['cart'][0]['productid']=$pid;
$_SESSION['cart'][0]['priceid']=$price;
$_SESSION['cart'][0]['qty']=$q;
}
}
function product_exists($pid){
$pid=intval($pid);
$max=count($_SESSION['cart']);
$flag=0;
for($i=0;$i<$max;$i++){
if($pid==$_SESSION['cart'][$i]['productid']){
$flag=1;
break;
}
}
return $flag;
}
?>
<?php
include("path/db.php");
include("path/functions.php");
if($_REQUEST['command']=='delete' && $_REQUEST['pid']>0){
remove_product($_REQUEST['pid']);
}
else if($_REQUEST['command']=='clear'){
unset($_SESSION['cart']);
}
else if($_REQUEST['command']=='update'){
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){
$pid=$_SESSION['cart'][$i]['productid'];
$q=intval($_REQUEST['product'.$pid]);
if($q>0 && $q<=999){
$_SESSION['cart'][$i]['qty']=$q;
}
else{
$msg='Some products not updated!, quantity must be a number between 1 and 999';
}
}
}
?>
<script language="javascript">
function del(pid){
if(confirm('Do you really mean to delete this item')){
document.form1.pid.value=pid;
document.form1.command.value='delete';
document.form1.submit();
}
}
function clear_cart(){
if(confirm('This will empty your shopping cart, continue?')){
document.form1.command.value='clear';
document.form1.submit();
}
}
function update_cart(){
document.form1.command.value='update';
document.form1.submit();
}
</script>
ASKER
ASKER
<script language="javascript">
function addtocart(pid,priceid){
document.form1.productid.value=pid;
document.form1.priceid.value=priceid;
document.form1.command.value='add';
document.form1.submit();
}
</script>
if ($_REQUEST['command']=='add' && $_REQUEST['productid']>0) {
$priceid=$REQUEST['priceid'];
$pid=$_REQUEST['productid'];
addtocart($pid, 1,$priceid);
header("location:shoppingcart.php");
exit();
}
function addtocart($pid,$q,$priceid){
if($pid<1 or $q<1) return;
if(is_array($_SESSION['cart'])){
if(product_exists($pid)) return;
$max=count($_SESSION['cart']);
$_SESSION['cart'][$max]['productid']=$pid;
$_SESSION['cart'][$max]['qty']=$q;
$_SESSION['cart'][$max]['priceid']=$priceid;
}
else{
$_SESSION['cart']=array();
$_SESSION['cart'][0]['productid']=$pid;
$_SESSION['cart'][0]['qty']=$q;
$_SESSION['cart'][0]['priceid']=$priceid;
}
}
ASKER
ASKER
ASKER
JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.
TRUSTED BY