Jump to content

KevinM1

Moderators
  • Posts

    5,222
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by KevinM1

  1. I'm not sure if this should be here or in the 'application design' section, so please move it to the right spot. I'm currently trying to save my shopping cart object so that when a customer moves from one page to another, their cart's information remains available.  Normally, I'd just save their cart in a database, save it when a page exits, and retrieve it when another page loads, but we're not using a database to store any client info (definitely not my design choice).  So, I basically have to pass the shopping cart from page to page (using sessions) without any database interaction whatsoever.  I'm not 100% sure how to do it, though.  I'm thinking of something along the lines of: [code] <?php include('../php_config/config.php'); //this autoloads my classes session_start(); if(!isset($_SESSION['cartInfo'])){   $myCart = new ShoppingCart(); } else{   $myCart = urldecode(unserialize($_SESSION['cartInfo'])); } . . . ?> [/code] My biggest concern is how to save the shopping cart before the user goes to a different page.  I'm not sure when to serialize and encode the object in my scripts.  I'm also wondering if I should make my shopping cart object a singleton, as logically there is only one cart available to the user. Any ideas?
  2. [quote author=onlyican link=topic=117877.msg481230#msg481230 date=1165600497] new is when declaring a class in php You dont need new in php for array $this -> Cart = array(); [/quote] Thanks for the help! :)
  3. I've created a simple shopping cart class that's supposed to store items of a different class in an array.  Unfortunately, I'm getting the following error in my tests: [quote]Parse error: syntax error, unexpected T_ARRAY, expecting T_STRING or T_VARIABLE or '$' in /home/thinkin8/php_classes/ShoppingCart.php on line 11[/quote] My class code in question is: [code] <?php class ShoppingCart extends Product{   private $Cart;   public function addProduct($name, $price, $quantity){       $this -> Cart[] = new Product($name, $price, $quantity);   }   public function clearCart(){       $this -> Cart = new array();   }   public function getTotal(){       $total = 0;       foreach($this -> Cart as $value){         $total += $value -> getPrice();       }       return $total;   }   public function showCart(){       echo "<table><tr><th>Name:</th><th>Quantity</th><th>Total Price</th></tr>\n";       foreach($this -> Cart as $value){         echo "<tr><td>$value->getName()</td><td>$value->getQuan()</td><td>\${$value->getPrice()}</td></tr>\n";       }   } } ?> [/code] The class it extends is: [code] <?php class Product{   private $Name;   private $Price;   private $Quantity;   public function __construct($name, $price, $quantity){       $this -> Name = $name;       $this -> Price = $price;       $this -> Quantity = $quantity;   }   public function getName(){       return $this -> Name;   }   public function getQuan(){       return $this -> Quantity;   }   public function getPrice(){       return ($this -> Price) * ($this -> Quantity);   }   public function showAll(){       echo "{$this -> Name}<br />\n";       echo "\${$this -> Price}<br />\n";       echo "{$this -> Quantity}";   } } ?> [/code] I'm using PHP 5.1.6, if that matters.  Please help. Thanks :)
  4. Nevermind, I found the problem.
  5. [quote author=thorpe link=topic=117447.msg479313#msg479313 date=1165354334] [code] <?php class Product{    private $Name;    private $Price;    private $Quantity;    public function __construct($name, $price, $quantity){       $this->Name = $name;       $this->Price = $price;       $this->Quantity = $quantity;    }    public function getPrice(){       return $this->Price * $this->Quantity;    } } ?> [/code] [/quote] This gives me the following error: [quote]Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /home/nights/www/www/PHP_stuff/classes/Product.php5 on line 9[/quote]
  6. I'm not sure why my autoload include appeared to be commented out, as it wasn't when I posted my code.  I never commented it out at all, actually. In any event, it looks like I've almost got it working.  Now I have the following error: [quote]Parse error: syntax error, unexpected T_PUBLIC in /home/nights/www/www/PHP_stuff/classes/Product.php5 on line 3[/quote] My Product class still remains the same: [code] <?php public class Product{   private $Name;   private $Price;   private $Quantity;   public function __construct($name, $price, $quantity){       this -> Name = $name;       this -> Price = $price;       this -> Quantity = $quantity;   }   public function getPrice(){       return (this -> Price) * (this -> Quantity);   } } ?> [/code] When I remove the 'public' before my class declaration, I then get a T_OPERATOR problem with the '->'.  I believe my syntax is basically correct, though, as the '$' isn't used for an object's properties when they're accessed, correct?
  7. [quote author=Crayon Violent link=topic=117462.msg479209#msg479209 date=1165344136] you can't do that.  what you would do is make a temporary variable that calls the function like $blah = nl2br($row['description']); and then use that variable inside the heredoc. [/quote] Thanks for the fast reply! :)  Any chance you'd mind taking a stab at my autoload question I have a few posts down? ;)
  8. Is it possible to use a function call within a heredoc if I use curly braces?  In other words, would something like the following correctly use nl2br and put the result in the output? [code] <?php echo <<<EOF <div> <!-- left side --> <img src="$row['pic_url']" alt="" /><br /> <p>{nl2br($row['description']);}</p> </div> <div> <!-- right side --> <p>$row['name']</p> <p>$row['price']</p> </div> EOF; ?> [/code]
  9. I hate to bump this, but I'd really like to know how to fix my error...it's annoying me greatly.
  10. I'm trying to test the autoload function, but I keep getting an error.  I have the following test code: [code] <?php include("config.php"); echo "Autoload test<br />\n"; $item = new Product('name', '24.99', '3'); foreach($item as $key => $value){    echo "$key -- $value<br />\n"; } ?> [/code] My config.php file is merely: [code] <?php function __autoload($className){    include("/PHP_stuff/classes/{$className}.php"); } ?> [/code] But I keep getting the following error: [quote]Fatal error: Cannot instantiate non-existent class: product in /home/nights/www/www/PHP_stuff/test2.php on line 7[/quote] According to my web hosting, I have access to both PHP 4.4.4 and 5.1.6...could not using the right version (presumably 5.1.6) be the cause of my problem?  If so, how can I switch versions?  If not, what am I doing wrong? Thanks :) EDIT: My product class, in case that matters: [code] <?php public class Product{    private $Name;    private $Price;    private $Quantity;    public function __construct($name, $price, $quantity){       this -> Name = $name;       this -> Price = $price;       this -> Quantity = $quantity;    }    public function getPrice(){       return (this -> Price) * (this -> Quantity);    } } ?> [/code]
  11. I'm currently designing a very simple online store.  I have two classes -- Product and ShoppingCart.  Both are pretty self-explanitory.  Product just ties a product's name together with its price.  ShoppingCart holds an array of Products. My concern is with the 'add to shopping cart' links the store will have.  I'm just not sure how to get the script to recognize the use of the 'add to shopping cart' links without having to rely on JavaScript.  Is there a way for me to do this without relying on JavaScript to serve as the go-between? Thanks. :)
  12. [quote author=taith link=topic=117013.msg477129#msg477129 date=1164996518] this should fix that problem :-) [code] <? function get_ip(){ if(!$ip=@$REMOTE_ADDR) $ip=$_SERVER['REMOTE_ADDR']; return $ip; } echo get_ip(); ?> [/code] [/quote] Sweet!  ;D  I completely forgot about REMOTE_ADDR...d'oh! :blush:
  13. For security reasons, I'd like to be able to get a user's IP address and check it against what's stored in a session variable to prevent hijacking.  Unfortunately, I'm not sure if PHP can get access to a user's IP address, so this is a two-part question: Can PHP 5+ (I'm not sure what version I have access to beyond that thanks to GoDaddy's luddite-esque approach to hosting) gain access to a user's IP address without any addon or extension, as I don't have direct access to the php.ini file? If not, I'm planning on using JavaScript to get that info...what would you suggest for the cleanest (and most secure) way of getting that info into PHP's hands so it can use it with sessions?  I'm thinking either a hidden input or a cookie, but I'd like to get some opinions on my choices. Thanks. :)
  14. Thanks for the help! :)
  15. While I wouldn't touch the program with a 10' pole, my boss has used Microsoft Frontpage to create all of the websites our company has created so far.  Because we're hosted by GoDaddy, we need to change from a Windows server to a Linux server in order for me to use PHP to create the online store (as I said in my post in the W.A.M.P. section of the board, GoDaddy has disabled PHP support on their Windows servers).  Will migrating from Windows to Linux break the sites because of Frontpage's extensions?
  16. Thanks for the help. :) Unfortunately, I found out that GoDaddy has disabled PHP support with their Windows servers, so it looks like I have to migrate everything over to Linux (which I prefer, but the migration will probably be tedious).
  17. I didn't want to pollute the main board with this, but I got a job!  Well, right now, it's a paid internship, but in a couple weeks I'll be working full time.  It's at a local startup computing solution company.  It's basically the owner, his wife, and myself running the show.  It should be interesting. Well, just wanted to share. :)
  18. I'm currently interning at a local startup computing solution company.  My main task is to get the online store up and running.  The website is hosted by GoDaddy.com, and is apparently on a Windows server.  Since I don't know ASP, I need to make the store using PHP and MySQL.  I was able to create the database without any problems through GoDaddy's rather well hidden control panel (they apparently hid it so the technically unaware couldn't screw things up), but I'm wondering if I'll run into problems using PHP in conjunction with the database because it's on a Windows server.  Are there any major pitfalls I should be aware of?  Unfortunately, I'm not sure what version of PHP GoDaddy uses -- they don't make that info publically available, from what I've been able to see. Thanks in advance. :)
  19. Over the next few weeks, I'm going to be working on a simple custom e-commerce site that will apparently be using SSL during transactions.  I know what SSL stands for, but beyond that, I'm clueless.  I also know that there's a PHP extension that deals with SSL (OpenSSL, I believe), but the spec is a bit confusing to me as I don't know the ins and outs of SSL.  Are there any resources you could direct me to that more or less explains the inner workings of SSL (things like certificates and whatnot)? Thanks. :)
  20. Over the next few weeks, I'm going to be working on a simple custom e-commerce site that will apparently be using SSL during transactions.  I know what SSL stands for, but beyond that, I'm clueless.  I also know that there's a PHP extension that deals with SSL (OpenSSL, I believe), but the spec is a bit confusing to me as I don't know the ins and outs of SSL.  Are there any resources you could direct me to that more or less explains the inner workings of SSL (things like certificates and whatnot)? Thanks. :)
  21. I've read that a lot of people use the __autoload() function to dynamically include whatever class files are needed.  I'm just wondering if I'm understanding how that's done: You put your defined __autoload() function inside of a file that's included in every other page (like a config file), right?  And the definition would be something along the lines of the following code, correct? [code] <?php function __autoload($className){   include ("../classes/{$className}.php"); } ?> [/code]
  22. Yeah, OO is pretty tricky in that regard.  If you were programming a game, then those examples would make more sense.  When I was at UNH, we basically used the OO capabilities of C++ to create our own abstract data types/structures.  For PHP, I think that's a better way to look at it.  A C++ OO example would be a dynamically allocated list, queue, or stack.  Or maybe an improved string data type. So, don't worry so much about what the examples create.  The important thing is knowing how classes are created and how you can use them.  They're basically just a way to make your own data structures.
  23. [quote author=ToonMariner link=topic=114122.msg464297#msg464297 date=1162916655] can it be done woithout paragraph tags? [/quote] I dunno..maybe.  You could do the same thing by putting them into their own div if you want, but I believe they need some kind of containing element to get the floats to clear properly with everything properly positioned on each line.  And what difference does it make, anyway?  You can change the separation between inputs by playing around with the paragraph's margins.  It's not that much more markup (about the same as what you originally posted with some extraneous divs) and it behaves properly, with the exception of your radio button text being not quite level with the button itself.
  24. This should work.  The 'Use as correspondee' text isn't quite even with the radio button, though. CSS: [code] form#delreg{   width: 765px; } fieldset{   border: 1px solid #939598; } #delreg label, #delreg input, #delreg textarea{   margin: 5px 10px;   float: left; } #delreg label{   float: left;   width: 130px;   text-align: right; } #delreg .bttn{   margin: 10px; } p {   clear: both;   margin: 5px; } [/code] HTML: [code] <?php //to get around the security measures that make it hard to post html code on the board ?> <form action="/delegate_reg.php" method="post" enctype="application/x-www-form-urlencoded" name="delreg" id="delreg">   <div id="dcont">       <fieldset>         <p><label for="name[0]"><span class="req">*</span>Delegate Name:</label><input type="text" name="name[0]" id="name[0]" value="" /></p>         <p><label for="phone[0]"><span class="req">*</span>Telephone:</label><input type="text" name="phone[0]" id="phone[0]" value="" /></p>         <p><label for="fax[0]">Fax:</label><input type="text" name="fax[0]" id="fax[0]" value="" /></p>         <p><label for="email[0]"><span class="req">*</span>Email:</label><input type="text" name="email[0]" id="email[0]" value="" /></p>         <p><label for="address[0]"><span class="req">*</span>Postal Address:</label><textarea name="address[0]" id="address[0]"></textarea>         <input type="radio" name="correspondee" value="0" checked="checked" />Use as Correspondee</p>         <p><label for="postcode[0]"><span class="req">*</span>Postcode:</label><input type="text" name="postcode[0]" id="postcode[0]" value="" /></p>       </fieldset>   </div>   <a href="javascript:tccAddDel();" title="Add Image">Add Another Delegate</a><br />   <input type="submit" class="bttn" name="submit" id="submit" value="Next" /> </form> <?php //one more time for good measure ?> [/code]
  25. [quote author=thorpe link=topic=114011.msg463682#msg463682 date=1162829305] [quote]Is the 'arrow' notation used in the first example always just representative of a truncated function name?[/quote] No. In the example mysqli is an object, not a function. [/quote] There doesn't seem to be much difference, though.  I mean, there are two ways to initialize it: [code] <?php $stmt =  $mysqli->stmt_init(); //the OO way $stmt = mysqli_stmt_init($link); //the procedural way ?> [/code] The former uses an object...is there a mysql object where it could be used in the way I theorized in my last post (code repeated below)? [code] <?php $dbc = $mysql -> connect($username, $host, $password); $db = $mysql -> select_db('dbname', $dbc); ?> [/code]
×
×
  • 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.