Jump to content

heartonsleeve

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

heartonsleeve's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Here's some other stuff, if that helps. The form for the product [code]<h3><?=$product_title?></h3> <div align="center"><img style="padding: 10px; border: 1px solid #4d4d4d;" src="http://www.indie-threads.com/store_images/<?=$main_image?>" alt="<?=$product_title?> by <?=$shop?>" /></div> <br /> <div style="width: 100%; "> <div style="float: right; width: 210px;"> <? if ($brand == aa){ ?> <img src="http://www.indie-threads.com/store_images/aasizing.gif" alt="American Apparel Sizing Chart" /> <? } ?> </div> <div style="float: left; width: 50%;"> <h2><strong>Description</strong></h2> <?=$long_description?> <p> <font style="font-size: 10px;">Sold by Indie Threads | Shipped by <a href="http://www.indie-threads.com/users/<?=$shop?>"><?=$shop?></a></font> </p> </div> </div> <p> <div align="center" style="clear: both;"> <form method="post" action="/cart.php"> <h3><strong>$<?=number_format($product_price,2)?></strong>&nbsp;   <select name="size">   <?   $attributes = mysql_query("SELECT * FROM product_attributes WHERE product_id = $product_id");       while($row = mysql_fetch_array($attributes)){         stripslashes(extract($row));   echo "<option>$attribute</option>";   }   ?> </select> </h3>       <input type="hidden" name="qty" value="1" />         <input type="hidden" name="req" value="add" /> <input type="hidden" name="product_id" value="<?=$product_id?>" /> <input type="hidden" name="shop" value="<?=$shop?>" />         <input type="image" src="store_images/add2cart.gif" value="buy me!" />       </form> </div> </p>[/code] And the cart.php which processes the form. [code]<?php include $_SERVER['DOCUMENT_ROOT'].   '/test_layout.php';   $cart = &new ShoppingCart; $cart_id = $cart->get_cart_id(); switch($_REQUEST['req']){   case "add":       $add2cart = $cart->cart_add($_REQUEST['product_id'], $_REQUEST['qty'], $_REQUEST['shop'], $_REQUEST['size']);             myheader("Shopping Cart");   include('featured_shop.php');   ?>   <div class="words">   <?       if(!$add2cart){         echo "<h3>Woops!</h3> The product could not be ".               "to your shopping cart. You may ".               "have entered an invalid quantity</center>";       } else {         header("Location: /cart.php");       }   ?>   </div>   <?       footer();    break;     case "update":       while(list($product_id, $qty) = each($_POST[qty])){         $sql = mysql_query("SELECT * FROM                       shopping_products                       WHERE product_id='$product_id'");                 $row = mysql_fetch_assoc($sql);         if($qty == 0){             mysql_query("DELETE FROM shopping_carts                   WHERE cart_identifier='$cart_id'                   AND                   product_id='$product_id'");         }                 if($qty > $row[product_qty]){             mysql_query("UPDATE shopping_carts                   SET product_qty='{$row[product_qty]}'                   WHERE cart_identifier='$cart_id'                   AND                   product_id='$product_id'");                                     $error = TRUE;                   $products[$product_id] = stripslashes($row[product_title]);                           } else {             mysql_query("UPDATE shopping_carts                   SET product_qty='$qty'                   WHERE cart_identifier='$cart_id'                   AND                   product_id='$product_id'");         }       }       if($error){         myheader("Shopping Cart"); include('featured_shop.php'); ?> <div class="words"> <?         echo "<center>You have selected more ".             "than our current stock for the following ".             "product(s): <br />";                 while(list($product_id, $product_name) = each($products)){             echo "<a href=\"/products.php?req=view&product_id=$product_id\">".                 "$product_name</a><br />";                }               echo "<br />";         echo "We have updated your quantity to the maximum ".               "value that we have in stock.</center><br />";         echo "<center><a href=\"/cart.php\">Back to Cart</a></center>"; ?> </div> <?         footer();       } else {         header("Location: /cart.php");       }         break;     case "remove":       $sql = mysql_query("DELETE FROM                   shopping_carts                   WHERE cart_identifier='$cart_id'                   AND product_id='{$_REQUEST['product_id']}'");       header("Location: /cart.php");                     break;     case "empty_confirm":       myheader("Shopping Cart");   include('featured_shop.php');   ?>   <div class="words">   <?       echo "<center>Are you sure ".             "you want to empty your cart?<br />".             "<a href=\"/cart.php?req=empty\">Yes</a>".             "&nbsp;|&nbsp;".             "<a href=\"/cart.php\">No</a></center>"; ?> </div> <?       footer();         break;   case "empty":       myheader("Shopping Cart");   include('featured_shop.php');   ?>   <div class="words">   <?       $cart->empty_cart();       echo "<center>Your cart has been emptied!</center>";   ?>   </div>   <?       footer();   break;         default:       myheader("Your Shopping Cart");         include('featured_shop.php');   ?>   <div class="words">   <?       if($cart_id){         $num_items = mysql_result(mysql_query("SELECT                         COUNT(*) as items                         FROM shopping_carts                         WHERE cart_identifier='$cart_id'"),0);         if($num_items == 0){             echo "<center>Your Shopping Cart is Empty!</center>";             footer();             exit();         }       } else {             echo "<center>Your Shopping Cart is Empty!</center>";             footer();             exit;       }       ?>       <h3>Your Shopping Cart</h3>       <div align="center" style="font-size: 11px; margin-bottom: 5px;">       This page allows you to modify or empty your shopping cart contents.       Simply change the number of each product you wish to purchase and       select the "Update Cart" link at the bottom.</div>       <form name="update" method="post" action="/cart.php">       <input type="hidden" name="req" value="update">       <table width="90%" border="0" cellspacing="0" cellpadding="4" align="center">       <tr>       <td><h2>Qty</h2></td>       <td><h2>Product</h2></td>       <td align="right"><h2>Price</h2></td>       <td align="right"><h2>Product Total</h2></td>       </tr>             <?php       $total = mysql_result(mysql_query("SELECT sum(product_qty * product_price) AS subtotal FROM shopping_carts WHERE cart_identifier='$cart_id'"),0);       $total = number_format($total, 2);                $sql = mysql_query("SELECT * FROM shopping_carts                   WHERE cart_identifier='$cart_id'") or die (mysql_error());             while($row = mysql_fetch_array($sql)){         $product_total = number_format(($row[product_qty] * $row[product_price]),2);         echo "<tr>".               "<td>".               "<input type=\"text\" name=\"qty[$row[product_id]]\" size=\"2\" value=\"$row[product_qty]\">".               "<br /><font size=\"2\">".               "<a href=\"/cart.php?req=remove&product_id=$row[product_id]\">Remove</a>".               "</td>".               "<td><a href=\"/products.php?req=view&product_id=$row[product_id]\">"               .stripslashes($row[product_title]).               "</a> by ".$row['shop']." - ".$row['size']."</td>".               "<td align=\"right\">\$".number_format($row[product_price], 2)."</td>".               "<td align=\"right\">\$$product_total</td>".               "</tr>";       }       ?>       <tr>       <td colspan="2">&nbsp;</td>       <td align="right">Total:</td>       <td align="right">$<?=$total?></td>       </tr>       <tr>       <td colspan="4" align="center">       <a href="javascript:void(document.update.submit())">Update Cart</a>       &nbsp;|&nbsp;       <a href="/cart.php?req=empty_confirm">Empty Cart</a>       &nbsp;|&nbsp;       <a href="/products.php">Continue Shopping</a>       &nbsp;|&nbsp;       <a href="/checkout.php">Checkout</a>       </td>       </tr>       </table>       </form>     </div>       <?php       footer();   break; } ?>[/code] ...anything?
  2. I'm working on setting up a shopping cart. I've got a class that was in a book, but I'm trying to modify it to allow products to have attributes. For example, I've got a t-shirt with sizes small, medium, large, and x-large. If I add a size small, everything is fine and it says the item that I have in size small. However, if I go back and add a medium, it just says that I have 2 smalls. Here's the shopping cart class: [code]<?php class ShoppingCart{   // Get the cart id   // If one is not available, make one.   function get_cart_id(){       if(!isset($_COOKIE['cid'])){         $cart_id = FALSE;       } else {         $cart_id = $_COOKIE['cid'];         $_SESSION['cid'] = $_COOKIE['cid'];       }       if($_SESSION['cid']){         $cart_id = $_SESSION['cid'];         if($_SESSION['login']){             @mysql_query("UPDATE members SET                 cart_id='$cart_id'                 WHERE id='".$_SESSION['userid']."'");         }       } else {         $cart_id = FALSE;       }       if(!$cart_id){         return FALSE;       } else {         return $cart_id;       }   }   function cart_add($product_id, $product_qty, $shop, $size){             $cart_id = $this->get_cart_id();             if(!$cart_id){         // if no cart id found, generate one         $unique_cid = md5(uniqid(rand(),1));                 // set cart id into the cookie         setcookie('cid', $unique_cid, time()+24*3600*60);                 // Register session with cart id value         $_SESSION['cid'] = $unique_cid;                 // if person is a member         // modify their profile with         // cart id in the database                 if($_SESSION['login']){             $_SESSION['cid'] = $unique_cid;             @mysql_query("UPDATE members SET                   cart_id='$unique_cid'                   WHERE id='".$_SESSION['userid']."'");         }       }       $sql_get_product = mysql_query("SELECT * FROM shopping_products                                     WHERE product_id='$product_id'");           $sql_check = mysql_query("SELECT * FROM shopping_carts                         WHERE                         cart_identifier='{$_SESSION['cid']}'                         AND product_id='$product_id'");             while($row = mysql_fetch_array($sql_check)){               $products = mysql_fetch_assoc($sql_get_product);                 if(($product_qty + $row[product_qty]) > $products[product_qty]){                   $new_qty = $products[product_qty];                 } else {                   $new_qty = ($product_qty + $row[product_qty]);                 }                                           $sql = mysql_query("UPDATE shopping_carts SET                           product_qty = '$new_qty',                           date = now()                           WHERE                           id='{$row['id']}'");               $skip = TRUE;       }        if(!$skip){             $products = mysql_fetch_assoc($sql_get_product);             if($products[product_qty] < $product_qty){               $product_qty = $products[product_qty];             }                         if($product_qty > 0){                       $sql = mysql_query("INSERT INTO shopping_carts                         (cart_identifier,                           product_id,                           product_title,                           product_qty,                           product_price,   shop,   size,                           date)                 VALUES ('{$_SESSION['cid']}',                   '$product_id',                   '$product_title',                   '$product_qty',                   '{$products['product_price']}',   '{$products['shop']}',   '$size',                   now())");             } else {               $sql = FALSE;             }                         }             if(!$sql){         return FALSE;       } else {         return TRUE;       }   }     function empty_cart(){ $cart_identifier = $this->get_cart_id(); $sql = @mysql_query("DELETE FROM shopping_carts               WHERE               cart_identifier='$cart_identifier'"); if(!$sql){ return FALSE; } else { return TRUE; } } } ?>[/code] I get the feeling that it's only doing this because it's reading the product_id but I don't know how to change it and I've been trying for way too long. Please help.
  3. *bump* I'd really appreciate a little more help with this.
  4. Okay, I tried that but now it's just killing all of my information. When I log in it takes me to my welcome page but if I try to go anywhere from there it takes me back to the login page. This is my login funtion. Do I need to change something in there as well? [code] function login_check(){     if($_SESSION['login'] != TRUE){       myheader("Login Required!");       include $_SERVER['DOCUMENT_ROOT'].               '/html/forms/login_form.html';       footer();       exit();   } }[/code]
  5. Sorry, I'm having trouble getting that to work. This is what my session looks like [code] <?php session_start(); session_name('IndieThreads'); header("Cache-control: private"); // Fix for IE ?> [/code] Do I put that code in there or on my layout.php page or my picture upload page?
  6. Sorry, this is the upload code I'm using. I would use what Jenk suggested but I'm hosted at Godaddy and their php version is older than what regenerate_session_id requires. [code] // Get a specific result from the "example" table $result = mysql_query("SELECT * FROM members WHERE member_id='$_SESSION[member_id]'") or die(mysql_error());  // get the first (and hopefully only) entry from the result $row = mysql_fetch_array( $result ); $old_pic = $row['profile_pic']; if ($_FILES['imagefile']['type'] == "image/gif"){ // random 4 digit to add to our file name // some people use date and time in stead of random digit $random_digit=rand(00000,99999); //combine random digit to you file name to create new file name //use dot (.) to combile these two variables $new_file_name=$random_digit . "_" . $_SESSION[username] . "_"; // Where the file is going to be placed $target_path = "users/images/" . $new_file_name; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['imagefile']['name']); // This is how we will get the temporary file... $_FILES['imagefile']['tmp_name']; $target_path = "users/images/" . $new_file_name; $target_path = $target_path . basename( $_FILES['imagefile']['name']); list($width, $height, $type, $attr) = getimagesize( $_FILES['imagefile']['tmp_name']); if ($width > 65 OR $height > 65){ echo "<h3>Whoa, there</h3><br />Your dimensions are too big. They need to be 65px x 65px. <a href=\"javascript:history.go(-1)\">Go back</a> and try again."; footer(); exit();} if(move_uploaded_file($_FILES['imagefile']['tmp_name'], $target_path)) {   echo "The file ". basename( $_FILES['imagefile']['name']). " has been uploaded<br /> <h3>Your new profile picture</h3> <br /><div align=\"center\"><img src=\"".$target_path."\"alt=\"$_SESSION[username]\" style=\"padding: 3px; border: 1px solid #6a7f92;\" /></div> <p><div align=\"center\"><a href=\"view_profile.php\">view your profile</a> | <a href=\"edit_profile.php\">edit your profile</a></div> </p>"; $image = $target_path ; if($row['profile_pic'] == "images/guest_pic.gif"){ echo ""; } elseif (file_exists($old_pic)) {   unlink($old_pic); print(""); } else {   print(""); } $sql = @mysql_query("UPDATE members SET profile_pic='$image' WHERE member_id='$_SESSION[member_id]'");   if(!$sql){       echo "Error inserting your information into MySQL: ".mysql_error();   } } else{     echo "There was an error uploading the file, please try again!"; } }elseif ($_FILES['imagefile']['type'] == "image/jpeg"){ // random 4 digit to add to our file name // some people use date and time in stead of random digit $random_digit=rand(00000,99999); //combine random digit to you file name to create new file name //use dot (.) to combile these two variables $new_file_name=$random_digit . "_" . $_SESSION[username] . "_"; // Where the file is going to be placed $target_path = "users/images/" . $new_file_name; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['imagefile']['name']); // This is how we will get the temporary file... $_FILES['imagefile']['tmp_name']; $target_path = "users/images/" . $new_file_name; $target_path = $target_path . basename( $_FILES['imagefile']['name']); list($width, $height, $type, $attr) = getimagesize( $_FILES['imagefile']['tmp_name']); if ($width > 65 OR $height > 65){ echo "<h3>Whoa, there</h3><br />Your dimensions are too big. They need to be 65px x 65px. <a href=\"javascript:history.go(-1)\">Go back</a> and try again."; footer(); exit();} if(move_uploaded_file($_FILES['imagefile']['tmp_name'], $target_path)) {   echo "The file ". basename( $_FILES['imagefile']['name']). " has been uploaded<br /> <h3>Your new profile picture</h3> <br /><div align=\"center\"><img src=\"".$target_path."\"alt=\"$_SESSION[username]\" style=\"padding: 3px; border: 1px solid #6a7f92;\" /></div> <p><div align=\"center\"><a href=\"view_profile.php\">view your profile</a> | <a href=\"edit_profile.php\">edit your profile</a></div> </p>"; $image = $target_path ; if($row['profile_pic'] == "images/guest_pic.gif"){ echo ""; } elseif (file_exists($old_pic)) {   unlink($old_pic); print(""); } else {   print(""); } $sql = @mysql_query("UPDATE members SET profile_pic='$image' WHERE member_id='$_SESSION[member_id]'");   if(!$sql){       echo "Error inserting your information into MySQL: ".mysql_error();   } } else{     echo "There was an error uploading the file, please try again!"; } } else { echo "<h3>Sorry</h3><br /> we only accept .gif and .jpg profile pictures. <a href=\"javascript:history.go(-1)\">Go back</a> and try a different image."; } [/code]
  7. [code] <?php include $_SERVER['DOCUMENT_ROOT']."/common.php"; function myheader($ptitle){ ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title><?php echo ($ptitle); ?></title> </head> <body onLoad="preloadImages();"> <div class="page_body"> <div align="right" class="account_area"> <? if($_SESSION['login'] == true){ ?> <div class="top_stuff_box"> <div class="top_stuff_words"> Welcome, <? echo $_SESSION[first_name];?> <div class="top_stuff_account"><a href="edit_profile.php">edit profile</a> &nbsp;|&nbsp; <a href="view_profile.php">view profile</a> &nbsp;|&nbsp; <a href="logout.php">logout</a></div> </div> <div class="top_stuff"> <img src="<? echo $_SESSION[profile_pic];?>" alt="<? echo $_SESSION[username];?>" style="padding: 3px; border: 1px solid #6a7f92;" /> </div> </div> </div> <? } else { ?> <div class="top_stuff_box"> <div class="top_stuff_words"> welcome, Guest <div class="top_stuff_account"><a href="login.php">sign in</a> &nbsp;|&nbsp; <a href="join.php">create an account</a></div> </div> <div class="top_stuff"> <img style="padding: 3px; border: 1px solid #6a7f92;" src="images/guest_pic.gif" alt="sampleprofile" /> </div> </div> </div> <? } ?> [/code] That's my layout.php page. $_SESSION[profile_pic] is what I'm having trouble with...
  8. Okay, I'm working on a site that deals with user profiles and everything is working pretty well. However, when a user tries to update their profile picture I've got it set up to delete their old one (only if the new one uploads successfully) and the session still calls the old one. If the user logs out and logs back in, it works just fine but is there a way I can skip that step?
  9. That looks a little better, but is there a way I can get rid of the word "Array" and all the arrows and whatnot? It's not a real huge deal if I can't, but it just seems like there should be a way to get rid of it. Right now it looks like this: Array ( [3] => Array ( [qty] => 1 [name] => Windmill Shirt [size] => small ) [2] => Array ( [qty] => 1 [name] => Robot Shirt [size] => small ) [1] => Array ( [qty] => 1 [name] => Goat Shirt [size] => small ) ) It takes up a little more room than I'd like it to.
  10. I'm working on a shopping cart and I've just about got everything set up and ready to go but one thing I'd like to fix is the way I can view what the customer ordered. They way the order has been recorded to the database is by serializing the multiple products someone has ordered. Then I unserialize it to view it and it just looks kind of strange. I can tell what's been ordered but is there anyway I can make it a little easier to read. [b]what it looks like when I view it unserialize:[/b] Array ( [3] => Array ( [qty] => 1 [name] => Windmill Shirt [size] => small ) [2] => Array ( [qty] => 1 [name] => Robot Shirt [size] => small ) [1] => Array ( [qty] => 1 [name] => Goat Shirt [size] => small ) ) and here's the code to serialize: [code] <?php $get_cart = mysql_query("SELECT * FROM                 shopping_carts                 WHERE cart_identifier='$cart_id'");                                while($row = mysql_fetch_array($get_cart)){       mysql_query("UPDATE shopping_products       SET product_qty = (product_qty - {$row['product_qty']})       WHERE product_id ='{$row['product_id']}'");        $storage_array[$row['product_id']]['qty'] = $row['product_qty']; $storage_array[$row['product_id']]['name'] = $row['product_title']; $storage_array[$row['product_id']]['size'] = $row['size'];       } $sproducts = serialize($storage_array);         mysql_query("INSERT INTO shopping_cart_orders               (order_date, token, products, total, type,               user_id, name, email, st_address, st_address2,               city, state, zip, country, zone, international)               VALUES (now(), '$token', '$sproducts', '$complete_total',               '$type', '{$_SESSION['userid']}', '$name', '$email',               '$st_address', '$st_address2', '$city', '$state', '$zip',               '$country', '$zone', '$international')") or die (mysql_error());                  // Empty the shopping cart                     //$cart->empty_cart(); ?> [/code] And here's the code to unserialize [code] <?       $sql = mysql_query("SELECT *                    FROM shopping_cart_orders                    ORDER BY orderid");       while($row = mysql_fetch_array($sql)){          stripslashes(extract($row));          $order=unserialize($products);                echo "<strong>$name made an order. They ordered the following:</strong><br />";          print_r ($order);          echo('<br /><br />');          echo "<strong>Ship To:</strong><br />                 $name<br />                $st_address                $st_address2<br />                $city, $state<br />                $zip<br />                $country<br /><br />";          echo "<strong>Their total was:</strong> $$total<br /><br /><hr style=\"width: 100%; border: solid 1px #000000;\" />";                         }       ?>       <? [/code] Any help would be greatly appreciated. Thanks.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.