Jump to content

dave_sticky

Members
  • Posts

    66
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Male
  • Location
    UK

dave_sticky's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Ah, Thanks! Very helpful. I'll just avoid leading numeric chars!
  2. Hi guys, I came across an interesting issue that I'm not sure I understand. Working on CSS for a website, I wanted to apply a class to an ID box. So... // The CSS #content { display: block; position: relative; float: left; width: 300px; height: 10px; border-width: 1px; border-style: solid; } #content.404 { border-color: #990000; } #content.blah { border-color: #990000; } // The HTML <div id="content" class="blah"></div> <!-- The above will give me a box with a red border, but... --> <div id="content" class="404"></div> <!-- That one gives me a box with a black border. They should be the same (ie, red). --> Does anyone have any idea why this would happen? Can CSS not handle certain characters when defining classes? Just a bit confused, as it took me about 45 minutes to realise this was happening, and I'd quite like to know what the problem is! Any thoughts very much appreciated. Thanks, Dave
  3. By the way, unless you've spotted this problem already you're going to have a whole world of issues with the shopping cart emptying / adding things to itself every time the page reloads. I'm going offline for the day soon, so if you get stuck, this should help: <?php error_reporting(E_ALL); ini_set('display_errors', '1'); session_start(); if(!isset($_SESSION['shopping_cart'])) { $_SESSION['shopping_cart'] = array(); } // And then to add items... // $_SESSION['shopping_cart'][] = "Ball"; // $_SESSION['shopping_cart'][] = "Shoe"; // Adding to Cart: if(isset($_GET['action']) && $_GET['action'] == "add_to_cart") { $_SESSION['shopping_cart'][] = $_GET['item']; } // Removing From Cart: if(isset($_GET['action']) && $_GET['action'] == "remove_item") { unset($_SESSION['shopping_cart'][$_GET['itemkey']]); } ?> <html> <head> </head> <body> <?PHP echo "<b>Shopping Cart</b><br />"; foreach($_SESSION['shopping_cart'] as $key => $value) { echo $value . " <a href='" . $_SERVER['PHP_SELF'] . "?action=remove_item&itemkey=" . $key ."'>Remove</a><br />"; } ?> <br /> <br /> <a href='<?PHP echo $_SERVER['PHP_SELF']; ?>?action=add_to_cart&item=Ball'>Add Ball to Cart</a><br /> <a href='<?PHP echo $_SERVER['PHP_SELF']; ?>?action=add_to_cart&item=Shoe'>Add Shoes to Cart</a> </body> </html>
  4. Ok, no probs mate. Glad to be of help. By the way, I was just tinkering with it on my local server... Probably best to use $_SERVER['PHP_SELF'] and not $_SERVER['REQUEST_URI'] if you're not using dynamic URLs... Otherwise you'll wind up with a very long url very quickly. If you are using dynamic URLs, you'll need to find some way of cleaning the link before echoing it out.
  5. Um... I don't know what your URL looks like, but if you're not using dynamic URLs (like index.php?page=page1 (or whatever)) you'll want to change the first & to a question mark <a href='<?PHP echo $_SERVER['REQUEST_URI']; ?>?action=add_to_cart&item=Ball'>Add To Cart Link</a> When you say "problems"... does it give you an error message?
  6. Well it's up to you, but personally I would use static pages to do it... Good luck with it!
  7. It is with a little bit of apprehension :-\ that I'm doing this, because I'm sure I'm about to open myself up to all sorts of ridiculing for wasting my time on a pointless (or indeed insecure / over engineered / processor power wasting) function, but after much looking around the net at Anti-SQL Injection stuff, I thought I'd steal borrow some ideas and create my own function... You know... For funsies. So, the idea of this function is that you can pass an array to it (like $_POST or $_GET) and it'll escape all the nasty characters for you so that you can safely build it into a query. Called like this: $safeArray = magicSlashes($_POST); function magicSlashes($array) { // To escape special characters for use in an SQL statement. global $link; // Database Connector. foreach ($array as $key => $value) { // For value in the array... if(get_magic_quotes_gpc()) { // If magic quotes is switched on... if(is_array($value)) { // And If we're looking at a multidimensional array (checkboxes)... foreach($value as $element) { // For each value in the sub array... $element = stripslashes($element); // Strip out magic_quotes' handywork... $safeArray[$key][] = mysql_real_escape_string($element,$link); // Escape it properly and put it in the safe array } // END FOREACH($value as $element). } else { // If we're not looking at a multidimensional array... $value = stripslashes($value); // Strip out magic_quotes' handywork... $safeArray[$key] = mysql_real_escape_string($value,$link); // Escape it properly and put it in the safe array } // END IF(is_array($value)). } else { // If magic quotes IS NOT on... if(is_array($value)) { // And If we're looking at a multidimensional array (checkboxes)... foreach($value as $element) { // For each value in the sub array... $safeArray[$key][] = mysql_real_escape_string($element,$link); // Escape properly and stick in the safe array. } } else { // if we're not looking at a multidimensional array... $safeArray[$key] = mysql_real_escape_string($value,$link); // Escape properly and stick in the safe array. } // END IF(is_array($value)). } // END IF(magic_quotes). } // END FOREACH($array as $key => $value). // Return the safe array. return $safeArray; } // END magicSlashes($array). I've not actually tested this, but it is based on a previous (and fully functioning) one that I did using addslashes() rather than mysql_real_escape_string(). Feedback / thoughts / critique / ridicule appreciated! Thanks Guys. (and sorry if I've posted this in the wrong area)
  8. Hmmm, Interesting... See Comments below... $url = $_SERVER["PHP_SELF"]; $name = Explode('/', $url); $name[count($name) - 1]; // Delete this line... Doesn't need to be there, and don't know if it will be causing problems $name = $name[count($name) - 1]; Other than that, when you say it doesn't work, what do you mean? Do you get an error message from the or die(mysql_error()); bit?
  9. Well as it is only 6 items, and in the absence of MySQL, I'd probably go with a static page for each item, and the code (or a modification of it) that I posted yesterday for the shopping cart. It would be by far the quickest way of implementing it. It will of course mean that it isn't very scalable - a new item would require a new file. Or alternately, get a server with MySQL on it!
  10. Theoretically yes, you could do it like this, but this will put a lot of processing on each page... Particularly if you've got a large shop - every time a page loads, the whole shop will load (behind the scenes) just to pull out the one item that needs to appear on the page.
  11. Yep, flat-file could be used if needed. Bit more complicated to set up and access though.
  12. Where are the three files (auth, authoconfig and check) in relation to generate_comment.php?
  13. Would this do the job? $array = array(array('value1')); [EDIT] Correction. That Won't. This will: // Level 1 $array = array('array1','array2'); // Level 2 $array[0] = array('value1','value2'); // Level 3 $array[0][0] = array('sub_value1'); Gives you: Array ( [0] => Array ( [0] => Array ( [0] => sub_value1 ) [1] => value2 ) [1] => array2 )
  14. Well you could add to it by having a "Add To Cart Link" which could pass the item to a script in the URL... <a href='<?PHP echo $_SERVER['REQUEST_URI']; ?>&action=add_to_cart&item=ItemName'>Add To Cart Link</a> if($_GET['action'] == "add_to_cart") { $_SESSION['shopping_cart'][] = $_GET['item']; } Remove is a little more tricky, but you'd need a remove link next to each item in the cart... foreach($_SESSION['shopping_cart'] as $key => $value) { echo $value . "<a href='" . $_SERVER['REQUEST_URI'] . "&action=remove_item&itemkey=" . $key ."'>Remove</a>"; } if($_GET['action'] == "remove_item") { unset($_SESSION['shopping_cart'][$_GET['itemkey']]); } This is all just off the top of my head, I've not tested it. But it's the basics of what you need to make it work!
  15. Sessions and Arrays... session_start(); $_SESSION['shopping_cart'] = array(); // And then to add items... $_SESSION['shopping_cart'][] = "Item 1"; $_SESSION['shopping_cart'][] = "Item 2"; // And to echo them back out... foreach($_SESSION['shopping_cart'] as $value) { echo $value . "<br />"; }
×
×
  • 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.