I am going to get fired if I can't fix this...
Posted: Wed Sep 07, 2005 5:43 pm
I am making a shopping cart and it keeps telling me ...
"Warning: Cannot use a scalar value as an array in /home/felonyfi/public_html/promo/newcart/includes/cart_classes.php on line 14"
here is the code... I have no idea what caused it... it is frustrating me to no end!!
"Warning: Cannot use a scalar value as an array in /home/felonyfi/public_html/promo/newcart/includes/cart_classes.php on line 14"
here is the code... I have no idea what caused it... it is frustrating me to no end!!
Code: Select all
<?php
include_once("functions.php");
include_once("session_functions.php");
class cart{
function cart(){
$this->time = time();
}
function addToCart($sku, $amnt="1"){
if(!isset($_SESSION['cart'])){
$_SESSION['cart'] = array();
}
if($sku != ""){
session_register('cart');
$_SESSION['cart'][$sku][] = $amnt; <-- line 14
return true;
}
return false;
}
function delete($sku){
if(isset($_SESSION['cart'][$sku])){
unset($_SESSION['cart'][$sku]);
}
$_SESSION['cart'][$sku];
}
function view(){
$shipping = 4;
$html = "<form method=\"GET\" action=\"cart_processor.php\">\n";
$html .= "<table border=\"0\" cellspacing=\"1\" cellpadding=\"0\" class=\"carttable\">\n";
$html .= " <tr class=\"carttableheader\">\n";
$html .= " <td><b>Remove</b></td>\n";
$html .= " <td><b>Product Name</b></td>\n";
$html .= " <td><b>Description</b></td>\n";
$html .= " <td><b>Qty</b></td>\n";
$html .= " <td><b>Price</b></td>\n";
$html .= " <td><b>Extended</b></td>\n";
$html .= " </tr>\n";
if(empty($_SESSION['cart'])){
$_SESSION['cart'] = array();
$tax = 0;
$tax = 0;
$total = 0;
$shipping = 0;
}
foreach($_SESSION['cart'] as $key => $val){
$num = $i % 2;
$product = new product();
$specs = $product->view("prod_sku", $key);
$thistotal = $specs['prod_price'] * $_SESSION['cart'][$key];
$thistotal = round($thistotal, 2);
$thistotal = sprintf("%.02f",$thistotal);
$html .= " <tr class=\"row".$num."\">\n";
$html .= " <td><input type=\"checkbox\" name=\"".$key."_remove\" value=\"1\"></td>\n";
$html .= " <td>".$specs['prod_name']."</td>\n";
$html .= " <td>".$specs['prod_description']."</td>\n";
$html .= " <td><input type=\"text\" name=\"".$key."_qty\" value=\"".$_SESSION['cart'][$key]."\" size=\"1\" maxlength=\"2\" /></td>\n";
$html .= " <td align=\"right\">".sprintf("%.02f",$specs['prod_price'])."</td>\n";
$html .= " <td align=\"right\">$thistotal</td>\n";
$html .= " </tr>\n";
$subtotal += $thistotal;
$totalamnt += $_SESSION['cart'][$key];
$i++;
}
$tax = $subtotal * .0725;
$tax = round($tax, 2);
$total = $shipping + $tax + $subtotal;
$_SESSION['tax'] = $tax;
$_SESSION['shipping'] = $shipping;
$_SESSION['subtotal'] = $subtotal;
$_SESSION['total'] = $total;
$html .= " <tr class=\"carttablepricing\">\n";
$html .= " <td colspan=\"4\" rowspan=\"4\" align=\"center\">This could be some information.</td>\n";
$html .= " <td align=\"right\"><b>subtotal</b></td>\n";
$html .= " <td align=\"right\">".sprintf("%.02f",$subtotal)."</td>\n";
$html .= " </tr>\n";
$html .= " <tr class=\"carttablepricing\">\n";
$html .= " <td align=\"right\"><b>Tax</b></td>\n";
$html .= " <td align=\"right\">".sprintf("%.02f",$tax)."</td>\n";
$html .= " </tr>\n";
$html .= " <tr class=\"carttablepricing\">\n";
$html .= " <td align=\"right\"><b>Shipping</b></td>\n";
$html .= " <td align=\"right\">".sprintf("%.02f",$shipping)."</td>\n";
$html .= " </tr>\n";
$html .= " <tr class=\"carttablepricing\">\n";
$html .= " <td align=\"right\"><b>Total</b></td>\n";
$html .= " <td align=\"right\">".sprintf("%.02f",$total)."</td>\n";
$html .= " </tr>\n";
$html .= " <tr class=\"carttablefooter\">\n";
$html .= " <td colspan=\"6\">\n";
$html .= " <table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n";
$html .= " <tr>\n";
$html .= " <td align=\"right\"><a href=\"".$_SERVER['PHP_SELF']."?action=destroycart\"><img src=\"images/emptycart.jpg\" border=\"0\"></a></td>\n";
$html .= " <td align=\"right\"><input type=\"hidden\" name=\"action\" value=\"updatecart\"><input type=\"image\" src=\"images/updatecart.jpg\"></form></td>\n";
$html .= " <td align=\"right\"><a href=\"index.php\"><img src=\"images/shopmore.jpg\" border=\"0\"></a></td>\n";
$html .= " <td align=\"right\">\n";
$html .= " <form method=\"post\" action=\"checkout.php\">\n";
$html .= " <input type=\"image\" src=\"images/order.jpg\"></td>\n";
$html .= " </form></td>\n";
$html .= " </tr>\n";
$html .= " </table>\n";
$html .= " </td>\n";
$html .= " </tr>\n";
$html .= "</table>\n";
echo $html;
}
function destroy(){
$_SESSION = array();
unset($_SESSION);
session_destroy();
}
}
class formProcess{
function formProcess($array){
$this->tax = $_SESSION['tax'];
$this->shipping = $_SESSION['shipping'];
$this->subtotal = $_SESSION['subtotal'];
$this->total = $_SESSION['total'];
$this->amnt = $_SESSION['amnt'];
$this->sku = $_SESSION['sku'];
$this->invoice = get_invoice();
$this->agree = $array['tosagree'];
$this->fname = $array['cust_first_name'];
$this->lname = $array['cust_last_name'];
$this->addr1 = $array['cust_addr'];
$this->addr2 = $array['cust_addr_2'];
$this->city = $array['cust_city'];
$this->state = $array['cust_state'];
$this->zip = $array['cust_zip'];
$this->zip = stripnum("-", $this->zip);
$this->cntry = $array['cust_cntry'];
$this->phone = $array['cust_phone'];
$this->phone = stripnum("-", $this->phone);
$this->pbusi = $array['cust_phone_2'];
$this->email = $array['cust_email'];
$this->bfname = $array['bill_first_name'];
$this->blname = $array['bill_last_name'];
$this->baddr1 = $array['bill_addr'];
$this->baddr2 = $array['bill_addr_2'];
$this->bcity = $array['bill_city'];
$this->bstate = $array['bill_state'];
$this->bzip = $array['bill_zip'];
$this->bcntry = $array['bill_cntry'];
$this->cc_name = $array['cc_name'];
$this->cc_numb = $array['cc_numb'];
$this->cc_type = $array['cc_type'];
$this->cc_exp_mo = $array['cc_exp_mo'];
$this->cc_exp_yr = $array['cc_exp_yr'];
$this->year = substr($this->cc_exp_yr, -2, 2);
$this->cc_cvv2 = $array['cc_cvv2'];
$this->cc_phone = $array['cc_phone'];
echo $this->cc_exp;
}
function validate(){
if(empty($this->fname)){
$wrong['cust_first_name'] = "notentered";
}
if(empty($this->agree) || $this->agree != "1"){
$wrong['tosagree'] = "notentered";
}
if(empty($this->lname)){
$wrong['cust_last_name'] = "notentered";
}
if(empty($this->addr1)){
$wrong['cust_addr'] = "notentered";
}
if(empty($this->city)){
$wrong['cust_city'] = "notentered";
}
if(empty($this->state)){
$wrong['cust_state'] = "notentered";
}
if(!empty($this->zip)){
if(strlen($this->zip) != 5){
if(strlen($this->zip) !=9){
$wrong['cust_zip'] = "orange";
}
}
}
else{
$wrong['cust_zip'] = "notentered";
}
if(empty($this->cntry)){
$wrong['cust_cntry'] = "notentered";
}
if(!empty($this->phone)){
if(strlen($this->phone) != 10){
$wrong['cust_phone'] = "orange";
}
}
else{
$wrong['cust_phone'] = "notentered";
}
if(!empty($this->email)){
if(!checkEmail($this->email)){
$wrong['cust_email'] = "orange";
}
}
else{
$wrong['cust_email'] = "notentered";
}
if(empty($this->bfname)){
$wrong['bill_first_name'] = "notentered";
}
if(empty($this->blname)){
$wrong['bill_last_name'] = "notentered";
}
if(empty($this->baddr1)){
$wrong['bill_addr'] = "notentered";
}
if(empty($this->bcity)){
$wrong['bill_city'] = "notentered";
}
if(empty($this->bstate)){
$wrong['bill_state'] = "notentered";
}
if(!empty($this->bzip)){
if(strlen($this->zip) != 5){
if(strlen($this->zip) !=9){
$wrong['bill_zip'] = "orange";
}
}
}
else{
$wrong['bill_zip'] = "notentered";
}
if(empty($this->bcntry)){
$wrong['bill_cntry'] = "notentered";
}
if(!empty($wrong)){
return $wrong;
}
return false;
}
function displayOrder(){
if(!empty($this->addr2)){
$addr2 = "<br>$this->addr2";
}
if(!empty($this->pbusi)){
$busi = "<br>Work: $this->pbusi";
}
$ccnum = xcredit($this->cc_numb);
$table = "<table class=\"conf\" border=0 cellspacing=0 cellpadding=3>\n";
$table .= " <tr>\n";
$table .= " <td class=\"heading\" colspan=2>Order Confirmation #$this->orderId</td>\n";
$table .= " </tr>\n";
$table .= " <tr>\n";
$table .= " <td class=\"heading2\">Billing Info</td>\n";
$table .= " <td class=\"heading2\">Shipping Info</td>\n";
$table .= " </tr>\n";
$table .= " <tr>\n";
$table .= " <td valign=\"top\">\n";
$table .= " <table class=\"info\" border=0 cellspacing=0 cellpadding=2>\n";
$table .= " <tr>\n";
$table .= " <td>\n";
$table .= " <p>$this->fname $this->lname<br>\n";
$table .= " $this->addr1 $addr2<br>\n";
$table .= " $this->city, $this->state $this->zip</p>\n";
$table .= " </td>\n";
$table .= " </tr>\n";
$table .= " <tr>\n";
$table .= " <td>\n";
$table .= " <p>Home: $this->phone $busi</p>\n";
$table .= " </td>\n";
$table .= " </tr>\n";
$table .= " <tr>\n";
$table .= " <td>\n";
$table .= " <p>$this->email</p>\n";
$table .= " </td>\n";
$table .= " </tr>\n";
$table .= " <tr>\n";
$table .= " <td>\n";
$table .= " <p>$this->cntry</p>\n";
$table .= " </td>\n";
$table .= " </tr>\n";
$table .= " </table>\n";
$table .= " </td>\n";
$table .= " <td valign=\"top\">\n";
$table .= " <table class=\"info\" border=0 cellspacing=0 cellpadding=2>\n";
$table .= " <tr>\n";
$table .= " <td>\n";
$table .= " <p>Lucas Visinoni<br>\n";
$table .= " 5047 Arden Way<br>\n";
$table .= " Paradise, CA 95969</p>\n";
$table .= " </td>\n";
$table .= " </tr>\n";
$table .= " <tr>\n";
$table .= " <td>\n";
$table .= " <p>United States</p>\n";
$table .= " </td>\n";
$table .= " </tr>\n";
$table .= " </table>\n";
$table .= " </td>\n";
$table .= " </tr>\n";
$table .= " <tr>\n";
$table .= " <td colspan=2>\n";
$table .= " <table class=\"info\" border=0 cellspacing=0 cellpadding=2>\n";
$table .= " <tr>\n";
$table .= " <td class=\"heading2\" colspan=\"2\">Credit Card Info</td>\n";
$table .= " </tr>\n";
$table .= " <tr>\n";
$table .= " <td>Name:</td>\n";
$table .= " <td>$this->cc_name</td>\n";
$table .= " </tr>\n";
$table .= " <tr>\n";
$table .= " <td>Card Type:</td>\n";
$table .= " <td>$this->cc_type</td>\n";
$table .= " </tr>\n";
$table .= " <tr>\n";
$table .= " <td>Card Number:</td>\n";
$table .= " <td>$ccnum</td>\n";
$table .= " </tr>\n";
$table .= " </table>\n";
$table .= " </td>\n";
$table .= " </tr>\n";
$table .= "</table>\n";
$this->order = $table;
return $table;
}
function checkCard(){
$date = getdate(time());
if(empty($this->cc_name) || $this->cc_name == " "){
return false;
}
if($this->cc_exp_yr == $date['year']){
if($this->cc_exp_mo < $date['mon']){
return false;
}
}
$ccnumber = removespace($this->cc_numb);
$ccnumber = trim($ccnumber);
$card = strrev($ccnumber);
$count = strlen($card);
$string = (string) $ccnumber;
$length = strlen($ccnumber);
if($this->cc_type == "mast"){
$check = substr($ccnumber, 0, 2);
$check = (integer) $check;
if($check >= 51 && $check <= 55){
if($length == 16){
$cardrules = 1;
}
}
}
elseif($this->cc_type == "visa"){
$check = substr($ccnumber, 0, 1);
$check = (integer) $check;
if($check == 4){
if($length == 13 || $length == 16){
$cardrules = 1;
}
}
}
elseif($this->cc_type == "amex"){
$check = substr($ccnumber, 0, 2);
$check = (integer) $check;
if($check == 34 || $check == 37){
if($length == 15){
$cardrules = 1;
}
}
}
elseif($this->cc_type == "dc"){
$check1 = substr($ccnumber, 0, 3);
$check2 = substr($ccnumber, 0, 2);
$check = (integer) $check;
if(($check1 >= 300 && $check1 <= 305) || $check2 == 36 || $check2 == 38){
if($length == 14){
$cardrules = 1;
}
}
}
elseif($this->cc_type == "disc"){
$check = substr($ccnumber, 0, 4);
$check = (integer) $check;
if($check == 6011){
if($length == 16){
$cardrules = 1;
}
}
}
elseif($this->cc_type == "jcb"){
$check1 = substr($ccnumber, 0, 1);
$check2 = substr($ccnumber, 0, 4);
$check = (integer) $check;
if($check2 == 1800 || $check2 == 2131 || $check1 == 3){
if($length == 15 || $length == 16){
$cardrules = 1;
}
}
}
for($i=0;$i<=$count;$i++){
if($i % 2 == 0){
$even[] = $card{$i};
}
else{
$odd[] = $card{$i};
}
}
foreach($odd as $val){
$double[] = ($val * 2);
}
$value = 0;
foreach($double as $val){
if(strlen($val) > 1){
$string = (string) $val;
$char1 = (integer) $string{0};
$char2 = (integer) $string{1};
$total = $char1 + $char2;
$evenvalue += $total;
}
else{
$evenvalue += $val;
}
}
foreach ($even as $val){
$oddvalue += $val;
}
$total = $evenvalue + $oddvalue;
$result = $total/10;
if(gettype($result) == "integer"){
$wellformed = 1;
}
if($cardrules == 1 && $wellformed == 1){
return true;
}
return false;
}
function convertValues(){
$exp = sprintf("%02s", $this->cc_exp_mo);
$inputs = "<h1>Order Summary:</h1>\n";
$inputs .= "<p><b>What you're ordering:</b><br />\n";
foreach($_SESSION['cart'] as $key => $val){
$product = new product();
if($specs = $product->view("prod_sku", $key)){
$inputs .= "$val: ".$specs['prod_name']."<br />\n";
}
}
foreach($_SESSION['cart'] as $key => $val){
$product = new product();
if($specs = $product->view("prod_sku", $key)){
$this->proddesc .= "$val: ".$specs['prod_name']." SKU:".$specs['prod_name'];
}
}
$inputs .= " Subtotal: ".sprintf("%.02f",$this->subtotal)."<br /> Tax: ".sprintf("%.02f",$this->tax)."<br /> Shipping: ".sprintf("%.02f",$this->shipping)."<br /> Total Cost: ".sprintf("%.02f",$this->total)."<br /></p>\n";
$inputs .= "<h1>Billing Address:</h1>\n";
$inputs .= "<p>$this->fname $this->lname<br />$this->addr1<br />$this->addr2<br />$this->city, $this->state $this->zip<br />$this->cntry</p>\n";
$inputs .= "<h1>Shipping Address:</h1>\n";
$inputs .= "<p>$this->bfname $this->blname<br />$this->baddr1<br />$this->baddr2<br />$this->bcity, $this->bstate $this->bzip<br />$this->bcntry</p>\n";
$inputs .= "<form method=\"post\" action=\"https://trans.atsbank.com/cgi-bin/trans.cgi\">\n";
$inputs .= "<input type=\"hidden\" name=\"action\" value=\"ns_quicksale_cc\">\n";
$inputs .= "<input type=\"hidden\" name=\"acctid\" value=\"PN6XN\">\n";
$inputs .= "<input type=\"hidden\" name=\"accepturl\" value=\"http://www.visionofdesign.com/thoughts/ordercompletetest.php\">\n";
$inputs .= "<input type=\"hidden\" name=\"declineurl\" value=\"http://www.visionofdesign.com/thoughts/ordercompletetest.php\">\n";
$inputs .= "<input type=\"hidden\" name=\"amount\" value=\".01\">\n";
$inputs .= "<input type=\"hidden\" name=\"ccname\" value=\"$this->cc_name\">\n";
$inputs .= "<input type=\"hidden\" name=\"ccnum\" value=\"$this->cc_numb\">\n";
$inputs .= "<input type=\"hidden\" name=\"expmon\" value=\"$this->cc_exp_mo\">\n";
$inputs .= "<input type=\"hidden\" name=\"expyear\" value=\"$this->cc_exp_yr\">\n";
$inputs .= "<input type=\"hidden\" name=\"usepost\" value=\"1\">\n";
$inputs .= "<input type=\"hidden\" name=\"ci_billaddr1\" value=\"$this->addr1\">\n";
$inputs .= "<input type=\"hidden\" name=\"ci_billaddr2\" value=\"$this->addr2\">\n";
$inputs .= "<input type=\"hidden\" name=\"ci_billcity\" value=\"$this->city\">\n";
$inputs .= "<input type=\"hidden\" name=\"ci_billstate\" value=\"$this->state\">\n";
$inputs .= "<input type=\"hidden\" name=\"ci_billzip\" value=\"$this->zip\">\n";
$inputs .= "<input type=\"hidden\" name=\"ci_billcountry\" value=\"$this->cntry\">\n";
$inputs .= "<input type=\"hidden\" name=\"ci_shipaddr1\" value=\"$this->baddr1\">\n";
$inputs .= "<input type=\"hidden\" name=\"ci_shipaddr2\" value=\"$this->baddr2\">\n";
$inputs .= "<input type=\"hidden\" name=\"ci_shipcity\" value=\"$this->bcity\">\n";
$inputs .= "<input type=\"hidden\" name=\"ci_shipstate\" value=\"$this->bstate\">\n";
$inputs .= "<input type=\"hidden\" name=\"ci_shipzip\" value=\"$this->bzip\">\n";
$inputs .= "<input type=\"hidden\" name=\"ci_shipcountry\" value=\"$this->bcntry\">\n";
$inputs .= "<input type=\"hidden\" name=\"ci_phone\" value=\"$this->phone\">\n";
$inputs .= "<input type=\"hidden\" name=\"ci_email\" value=\"$this->email\">\n";
$inputs .= "<input type=\"hidden\" name=\"ci_memo\" value=\"$this->proddesc\">\n";
$inputs .= "<input type=\"hidden\" name=\"emailfrom\" value=\"no-reply@felonyfights.com\">\n";
$inputs .= "<input type=\"hidden\" name=\"emailsubject\" value=\"Purchase Receipt\">\n";
$inputs .= "<input type=\"hidden\" name=\"ci_ipaddress\" value=\"".$_SERVER['REMOTE_ADDR']."\">\n";
$inputs .= "<input type=\"hidden\" name=\"merchantordernumber\" value=\"$this->invoice\">\n";
$inputs .= "<input type=\"hidden\" name=\"cvv2\" value=\"$this->cc_cvv2\">\n";
$inputs .= "<input type=\"image\" src=\"images/ordernow.jpg\">\n";
return $inputs;
}
}
class orderProcess{
function orderProcess($array){
$this->Status = $array['Status'];
$this->Reason = $array['Reason'];
$this->Authno = $array['AuthNo'];
$this->Version = $array['Version'];
$this->historyid = $array['historyid'];
$this->orderid = $array['orderid'];
$this->PostedVars = $array['PostedVars'];
$this->action = $array['action'];
$this->acctid = $array['acctid'];
$this->accepturl = $array['accepturl'];
$this->declineurl = $array['declineurl'];
$this->amount = $array['amount'];
$this->ccname = $array['ccname'];
$this->expmon = $array['expmon'];
$this->expyear = $array['expyear'];
$this->usepost = $array['usepost'];
$this->ci_billaddr1 = $array['ci_billaddr1'];
$this->ci_billaddr2 = $array['ci_billaddr2'];
$this->ci_billcity = $array['ci_billcity'];
$this->ci_billstate = $array['ci_billstate'];
$this->ci_billzip = $array['ci_billzip'];
$this->ci_billcountry = $array['ci_billcountry'];
$this->ci_shipaddr1 = $array['ci_shipaddr1'];
$this->ci_shipaddr2 = $array['ci_shipaddr2'];
$this->ci_shipcity = $array['ci_shipcity'];
$this->ci_shipstate = $array['ci_shipstate'];
$this->ci_shipzip = $array['ci_shipzip'];
$this->ci_shipcountry = $array['ci_shipcountry'];
$this->ci_phone = $array['ci_phone'];
$this->ci_email = $array['ci_email'];
$this->ci_memo = $array['ci_memo'];
$this->emailfrom = $array['emailfrom'];
$this->emailsubject = $array['emailsubject'];
$this->ci_ipaddress = $array['ci_ipaddress'];
$this->merchantordernumber = $array['merchantordernumber'];
$this->cvv2 = $array['cvv2'];
}
function process(){
if(strtolower($this->Status) == "approved"){
return true;
}
if(strtolower($this->Status) == "declined"){
return false;
}
else{
return false;
}
}
function addToDb(){
echo $this->AuthNo."asdfasdf";
$sql = "
UPDATE `order` SET
`order_Status` = '$this->Status',
`order_Reason` = '$this->Reason',
`order_AuthNo` = '$this->AuthNo',
`order_Version` = '$this->Version',
`order_historyid` = '$this->historyid',
`order_orderid` = '$this->orderid',
`order_PostedVars` = '$this->PostedVars',
`order_action` = '$this->action',
`order_amount` = '$this->amount',
`order_ccname` = '$this->ccname',
`order_expmon` = '$this->expmon',
`order_expyear` = '$this->expyear',
`order_ci_billaddr1` = '$this->ci_billaddr1',
`order_ci_billaddr2` = '$this->ci_billaddr2',
`order_ci_billcity` = '$this->ci_billcity',
`order_ci_billstate` = '$this->ci_billstate',
`order_ci_billzip` = '$this->ci_billzip',
`order_ci_billcountry` = '$this->ci_billcountry',
`order_ci_shipaddr1` = '$this->ci_shipaddr1',
`order_ci_shipaddr2` = '$this->ci_shipaddr2',
`order_ci_shipcity` = '$this->ci_shipcity',
`order_ci_shipstate` = '$this->ci_shipstate',
`order_ci_shipzip` = '$this->ci_shipzip',
`order_ci_shipcountry` = '$this->ci_shipcountry',
`order_ci_phone` = '$this->ci_phone',
`order_ci_email` = '$this->ci_email',
`order_ci_memo` = '$this->ci_memo',
`order_emailfrom` = '$this->emailfrom',
`order_ci_ipaddress` = '$this->ci_ipaddress',
`order_merchantordernumber` = '$this->merchantordernumber',
`order_cvv2` = '$this->cvv2',
`order_date` = '".time()."'
WHERE `order_id` = $this->merchantordernumber LIMIT 1";
echo $sql;
}
}
?>