Jump to content

parapet74

Member
  • Posts

    10
  • Joined

  • Last visited

Everything posted by parapet74

  1. Thanks for the reply and sample code. I wasn't able to get it to work, probably due to not knowing quite where to put things. I've had minimal success with jquery by inserting the code in the <head> between <script> tags. My code now looks like this: function render_products_from_mysql() { $products = get_mysql_products() ; if ($products == FALSE) { $output = '<table class="products">' ; $output.= '<tr><td>No products to display.</td></tr>' ; $output.= '</table>' ; } else { $output = '<div class="shoptable">' ; $output.= ' <table class="products">' ; $output.= '<tr id="tbl_head">' ; $output.= '<td class="prodhdchek"></td>' ; $output.= '<td class="prodhdicon"> </td>' ; $output.= '<td class="prodhditem"><h3>Item</h3></td>' ; $output.= '<td class="prodhddesc"><h3>Description</h3></td>' ; $output.= '<td class="prodhdprix"><h3>Price</h3></td>' ; $output.= '</tr>' ; foreach ($products as $product) { $output .= '<tr> <td class="prodchek"> <div id="mt'.$product['id'].'"><img src="./public/images/emptychk.jpg" height="40" width="40" /></div> <div id="grn'.$product['id'].'"><img src="./public/images/greenchk.jpg" height="40" width="40" /></div> </td> <td class="prodicon"><img src="'.$product['image'].'" height="15" width="15" /></td> <td class="proditem"><h4>'.$product['title'].'</h4></td> <td class="proddesc">'.$product['description'].'</td> <td class="prodprix">$'.number_format($product['price'], 2).'</td> <td class="prodhdhref"><a href="./addToCart.php?id='.$product['id'].' id="atc'.$product['id'].'">add to cart</a> <a href="./removeFromCart.php?id='.$product['id'].' id="rfc'.$product['id'].'" style="display:none;">Remove from Cart</a> </tr>' ; } } $output .= '</table>' ; return $output ; } and <?php //// addToCart.php //// require_once '../functions/functions.php'; $shopping_cart = get_shopping_cart() ; echo render_header(); $product_id = $_REQUEST['id'] ; If (product_exists($product_id)) { $shopping_cart->AddItem($product_id) ; } set_shopping_cart($shopping_cart) ; echo render_products_from_mysql() ; echo render_footer() ; ?> The JQuery code, inserted into the <head> section, DOES display the green checked box, but only for a moment and then it reverts. My code is deficient in the following ways: 1) Code fires whenever I click ANY anchor tag... I intend to narrow that down to only AddToCart clicks. 2) greenchk.jpg DOES replace the emptychk.jpg, but only for a half-second and then it reverts 3) No matter where I click, the top row checkbox is the only one that changes. I have now set unique IDs for each mt/grn tag, but need assistance breaking out the uniqueness ($product.['id']) and using it to swap the appropriate jpg 4) I also wish to swap the "Add To Cart" anchor for a "Remove From Cart" anchor Here's the relevant part of my <head> section: <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> $(function() { $("a").click(function(){ $("#mt").hide(); $("#grn").show(); }); }); </script>
  2. I am modifying the Shopping Cart tutorial to create multiple rows, with one product per row (like a spreadsheet). Each row begins with the img of a large, empty checkbox (emptychk.jpg) and ends with the usual "add to cart" <a href> tag. When someone clicks the add-to-cart <a href> at the end of any product row, I would like to: A - change the anchor tag to "remove from cart" ; and B - change img emptychk.jpg to a different image (greenchk.jpg) C - Ideally, I would like clicking on the empty checkbox <img> (at the start of any row) to do the same thing as clicking <a href>add to cart </a> for that row. Is that possible? How could that be done? I am guessing that questions A and B would happen inside the addToCart.php script, but I'm stuck there. Note that my addToCart.php file is exactly the same as at the end of Ben's video (converted from XML to SQL db) function render_products_from_mysql() { $products = get_mysql_products() ; if ($products == FALSE) { $output = '<table class="products">' ; $output.= '<tr><td>No products to display.</td></tr>' ; $output.= '</table>' ; } else { $output = '<div class="shoptable">' ; $output.= ' <table class="products">' ; $output.= '<tr>' ; $output.= '<td class="prodhdchek">Buy</td>' ; $output.= '<td class="prodhdicon"> </td>' ; $output.= '<td class="prodhditem"><h3>Item</h3></td>' ; $output.= '<td class="prodhddesc"><h3>Description</h3></td>' ; $output.= '<td class="prodhdprix"><h3>Price</h3></td>' ; $output.= '</tr>' ; foreach ($products as $product) { $output .= '<tr> <td class="prodchek"><img src="./public/images/emptychk.jpg" height="40" width="40" /></td> <td class="prodicon"><img src="'.$product['image'].'" height="15" width="15" /></td> <td class="proditem"><h4>'.$product['title'].'</h4></td> <td class="proddesc">'.$product['description'].'</td> <td class="prodprix">$'.number_format($product['price'], 2).'</td> <td class="prodhdhref"><a href="./addToCart.php?id='.$product['id'].'">add to cart</a> </tr>' ; } } $output .= '</table>' ; return $output ; } <?php //////////////////// addToCart.php ///////////////////////////////// require_once '../functions/functions.php'; $shopping_cart = get_shopping_cart() ; echo render_header(); $product_id = $_REQUEST['id'] ; If (product_exists($product_id)) { $shopping_cart->AddItem($product_id) ; } ?> <table class='shoppingCartCheckout'> <tr class='shoppingCartCheckoutHeader'> <th>Product ID</th> <th>Quantity</th> <th>Amount</th> </tr> <?php $line_item_counter = 1 ; foreach($shopping_cart->GetItems() as $product_id) { echo render_shopping_cart_row($shopping_cart, $product_id, $line_item_counter) ; $line_item_counter++ ; } echo render_shopping_cart_subtotal_row($shopping_cart) ; echo render_shopping_cart_tax_row($shopping_cart) ; echo render_shopping_cart_total_row($shopping_cart) ; ?> </table> <?php set_shopping_cart($shopping_cart) ; ?> <?php echo render_footer() ; ?>
  3. Thanks -- I hadn't heard about FirePHP. Installed it and enabled the NET panel in FireBug, but still no success. I am now getting this message in the view: Notice: Use of undefined constant console - assumed 'console' in C:\xampp\htdocs\wmp\inc\mysql.class.php Does my code look correct? Do I need to do something else to "start" FirePHP? -- EDIT -- Found the solution(s) - FirePHP is not a simple Firefox add-on... I've now downloaded the FireHPCore folder and installed it as per instructions on the garish http://www.firephp.org/HQ/Learn.htm page, and ... it's working. Quite different (code also) from the video, but it works! Thanks Ben.
  4. Another tutorial that would be of great benefit would be a comprehensive overview of website security, "for dummies", aimed at the Shopping Cart and PHP customers. As a novice php-er, I realize there are security issues I must learn about. For eg, I've seen the term "SQL injectors" mentioned in various places. Also, that passwords should be encrypted using MD5 (how does one do that??) A video, or a text article, that covers the following would be of great interest: - quick overview of web site security, from the HOSTED programmer perspective * eg. What is my responsibility, and what will my hosting provider take care of? * how secure are the files and folders under my public-html (ie. "htdocs" equiv) folder? * are some folders less secure than others? * can users view my php code? How easily? Is it possible to prevent that? * how do I log into the MySQL database with a username/password if I must write the password into a PHP script? * are there security differences between html and php files? * are there any advantages to using ruby on rails over PHP? * Security issues like SQL injectors and how to protect oneself from them * Other security issues? * Encrypting passwords before storing in SQL database * converting images to Base64 and storing/retrieving from SQL table - is there any advantage to doing this? (Look at WAMPSERVER's index.php file)
  5. This function is being called and does log me into the SQL db, but I don't see the success message in Firebug's console: function connectToDb () { // Make connection to MySQL server if (!$this->dbConn = @mysql_connect($this->host, $this->dbUser, $this->dbPass)) { trigger_error('Could not connect to server'); $this->connectError=true; // Select database } else if ( !@mysql_select_db($this->dbName,$this->dbConn) ) { trigger_error('Could not select database'); $this->connectError=true; } else { console.log("Successful connection to MySQL database"); } }
  6. Trying to understand some php code... What do the ? and : operators do? What will be in $s? $cart = $_SESSION['cart']; $items = explode(',',$cart); $s = (count($items) > 1) ? 's':'';
  7. parapet74

    Tutorial Request

    I purchased your complete Php programmer course and am working through it. I need more info regarding debugging. I've watched Ben's video on debugging php, which was pretty basic, but Jon's videos also cover using print_r() and the Firefox Firebug add-in with its console.log command. However, the code he writes doesn't work on my system -- I don't get any output to the Firebug console. Perhaps it's because I use Windows... or maybe versionitis. It would be really great if you guys could put together a comprehensive debugging tutorial, covering the most helpful tools. For example, Are there other external tools you guys use besides Firebug? Why wouldn't the same console.log code Jon writes in his videos work on my Windows pc? Everything else works... (and yes, Firebug is installed and working). How to pop-up an alert() and display variable contents. Using the var_dump command. Echo and print_r() - when to use each. Making one or the other work in various situations (e.g. - in the middle of JQuery code, in HTML, in Php, etc.) Having all these topics in a single video (or written tutorial) would help immensely. I've been trying to remember where I saw Jon use console.log and have looked through 6 videos so far, and still haven't found any -- yet I know I've watched him use it at least 3 times. Please keep the pace fast. I typically watch a video several times (only the first time playing at normal speed), using rewind frequently. Great work, Stefan et al. You are creating a good resource, well worth the money.
  8. Thanks for the speedy reply. Yes to all of your questions. EXCEPT... as I'm thinking about it... the third one. I was entering this address into the address bar: file:///c:/xampp/htdocs/killerphp/index.php -- which *is* on my localhost... but your reply got me thinking... Typing http://localhost/killerphp/index.php worked. Embarrassingly basic. Thanks for the brain nudge.
  9. Php code is not being executed. My config: WinXP P5 2Gb/500Gb XAMPP (latest DL) -- also tried with WAMPSERVER (latest DL) Firefox, Chrome, Opera and Safari (all current) HTML renders, but php is skipped. <!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 utf-0" /> <title>SESSIONS TUTORIAL</title> </head> <body> <h2>This displays correctly</h2> <br> <p> <?php echo "This does not display" ; ?> </p> </body> </html> I have tried: - switching from WAMP to XAMPP and back - reinstall each of the above (just the "out of box" config, but ensured Apache is running) - full reimage/restore of C:, then reinstall each of the above - tried in all browsers - <?php ... ?> (using long tags) - with / without semi-colon after echo statement I'm new to PHP and to programming, so I'm probably missing something embarrassingly basic. Either in the code, or in my WAMP setup. Au secours?
×
×
  • Create New...