This repository has been archived by the owner on Sep 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddtocart.php
99 lines (77 loc) · 2.65 KB
/
addtocart.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
ob_start();
?>
<?php
include_once "assembly.css";
include_once "top.php";
//session_start();
?>
<body class="body">
<div class='content'>
<article class='topcontent'>
<?php
if((isset($_REQUEST["qty"])))
{
if ($_REQUEST["qty"]=='0/0' or $_REQUEST["qty"]==0)
$quantity=1;
else if( $_REQUEST["qty"] >25)
$quantity=25;
else
$quantity=$_REQUEST["qty"];
$itemcode=$_COOKIE["code"];
$itemprice=$_COOKIE["iprice"];
$itemdsptn=$_COOKIE["idcriptn"];
$itemname=$_COOKIE["itemname"];
if(!isset($_GET['cartflag']))
{
mysql_connect("localhost","root","")or die("could not set connectn");
mysql_select_db("shop")or die("could not connect to db");
$tabname=session_id();
$query="INSERT INTO ".$tabname." values('$itemcode','$itemname','$itemdsptn','$itemprice','$quantity')";
mysql_query($query);
}
echo "<content>";
echo 'Item ADDED to CART .<br>U can make CHANGES here in quantity of purchased product<br>';
echo 'Click on <a href="index.php?flag=cart">CART</a> to view your items';
echo "<table border=\"1\">";
echo "<tr><td><b>item code</b></td><td><b>item name</b></td><td><b>item description</b></td><td><b>item price</b></td><td><b>Quantity</b></td><td><b>change Quantity</b></td></tr>";
echo "<tr><td>".$itemcode."</td><td>".$itemname."</td><td>".$itemdsptn."</td><td>".$itemprice."</td><td>".$quantity;
?>
<script type="text/javascript">
function numbersonly(e)
{
var key=e.charCode? e.charCode : e.keyCode
if (key!=8){
if (key<48||key>57)
return false
}
}
</script>
<?php
echo "</td><td><form action='addtocart.php?cartflag=1' method='POST' onkeypress=\"return numbersonly(event)\" ><input type=\"text\" name=\"qty\" style='width:20px'><input type=\"submit\" value='Click To CHANGE' ></td>";
echo "<br/><br/>";
$conn=mysql_connect("localhost","root","")or die("could not set connectn");
mysql_select_db("shop")or die("could not connect to db");
$tabname=session_id();
//echo $tabname;
if(isset($_GET['cartflag']))
{ if($_GET['cartflag']==1)
{ //echo $itemcode;
$query = "UPDATE". $tabname." SET quantity='".$quantity."' WHERE icode like '%".$itemcode."'";
mysql_query($query)or die('error while updating value');
}
}
else {
$query="INSERT INTO ".$tabname." values('$itemcode','$itemname','$itemdsptn','$itemprice','$quantity')";
mysql_query($query) ;
}
mysql_close($conn);
echo "</content>";
}
?>
</article>
</div>
</body>
<?php
ob_flush();
?>