Jump to content

cpd

Members
  • Posts

    883
  • Joined

  • Last visited

  • Days Won

    5

Everything posted by cpd

  1. It's quite apparent to me you know very little and have a minimal understanding of the language and how to get data from a database. Before trying to create a login script which is probably quite advanced for you, go and learn how to successfully retrieve data from a database and how to create/destroy/manage PHP sessions... We can't lecture on these topics due to their wide scope. You will need to do the research yourself. Start with google and anything you don't understand specifically, google as well. Just don't stray to far from your objective.
  2. Print out your $item variable and see what it contains (do it directly after you set it) if it comes out correctly its to do with whatever code comes after that. If not than its something to do with posting your data to the header or the way your retrieving it.
  3. Just because your value has a dot it doesn't mean PHP will treat it as the concatenation symbol. It treats the value as, most likely, a string and the dot is part of that string...
  4. Aye? If they're logged in and you've got the user ID in a session already, just use that to query the database with a simple select T-SQL statement...
  5. I've no idea how you've managed to generate two different array keys: "item" and "item_id". If your script isn't assigning the item id or item name (not entirely sure from that array which your trying to use) then its likely the "item" variable isn't actually being set properly. Ensure all your data is being correctly posted to the header and all your form names match up correctly with whatever your trying to access in the $_POST variable. It may just be a simple typo. You also need to review the code which sets a new item and which increases the quantity by 1 to ensure all the array keys match up which is what I referred to in my first sentence.
  6. Any links given to you about login scripts will most probably contain a load of crap which you don't need to understand for your problem. All you need to do is authenticate the user when they submit the login form. Then create a session called something like "username" and assign the username they logged in with as the value. Every time they go on to a new page you can then run a function or something to retrieve all their details from the database. If you don't know what I mean by session look up sessions via google... else we could be here for hours giving you links and trying to explain everything to you.
  7. It'll be a lot easier to use a session and select all the information you want from the database using some form if ID which is unique to the person logged in.
  8. Looking at you original code your seriously confusing yourself. One thing has already been pointed out to you but just to reiterate that point: if you use the following code you will be reassigning your 1 key in your cart to whatever the new item is. You will not be creating new entries. $_SESSION['cart_array'] = array(1 => array('item' => $item, 'quantity' => 1)); To create a new entry into an array you must use what Drummin suggested: $_SESSION['cart_array'][] = array('item' => $item, 'quantity' => 1); This will increment your car_array array key by 1 for each new entry. Furthermore, you are repeatedly opening and closing the PHP output buffer by opening and closing PHP tags. This could, in large scripts, cause slow execution and is very bad practice. The first four lines in your "shopping cart" page should all be within a single <?php tag. Regarding your actual logic I think its in a bit of a tangle. Break down the steps and worry about the actual programming later. Steps [*]Test if an item has been submitted. [*]Determine if the item already exists in the cart. [*]If already exists: increment item quantity by 1 or the value specified depending on how your system functions. [*]Else: Add item to cart with a quantity value of 1. [*]Then display a success message [Optional] Your sort of already doing this but in a rather muddle. So lets break each step down individually Test if an item has been submitted. Simple enough so we wont bother going over it. Determine if the item already exists in the cart. Perhaps create a function for this along the lines of function cartItemExists($newItem){ foreach($_SESSION['cart'] as $key=>$item){ if(key($item) == $newItem) return $key; } return false; } Use this in a simple if statement and you can move on to the next step. Notice if the item already exists it will return an array key which can be used to increment the cart item as your SESSION['cart'] looks something like: array(cart => array( 1 => array(item=>value) 2 => array(item=>value) 3 => array(item=>value) ) So you must know which value, 1, 2 or 3, you need to use to get the item. I'm going to assume you can continue from here and write the logic for the next few steps. Just for the record, you can combine all of this into a single function or putting it directly into your script but I wanted to break it down for you so you understand how to construct your script in the future. Please note I also used a slightly different array structure to the one you were using as it made more sense to me to use the array key as the item name and the value as the quantity. You can do whatever you want, neither is correct nor wrong. Good attempt though.
  9. You should group by columns only. You do not need to specify what values to group by. The MySQL Server will do this automatically.
  10. SELECT * FROM `table` WHERE `column` LIKE '%{$value}%'; % is a wildcard. In this instance it means search for a term with anything either side of it. If you were to put '{$value}%' it would only allow for additional characters after the term and vice-versa.
  11. From what I've read your overcomplicating things and confusing yourself. Are you trying to multiply columns K001, K002, and total by 22? If so, why are you doing that when you need the total? Unless I've completely misinterpreted your problem.
  12. In answer to the topic title. if(!is_array($var){ Might still be worth testing for it in-case someone has once again edited the HTML.
  13. if (strpos($_SERVER['REQUEST_URI'], 'component') !== false) { echo '<div id="stuffdiv">stuff</script></div>'; // You do not need to escape the double-quotes unless you create the string using double quotes. }
  14. You could group by and then only show the first 5 for each. This however splits your logic between the MySQL Server and PHP; not the end of the world. If you wanted all the logic in the MySQL server you've got a painful query ahead of you...
  15. Or a view. Queries can automatically be cached if repeatedly called as well... I believe caching is on by default.
  16. When you submit the form, the data is posted to the header and passed to the action page specified in the form tags; if none is specified it will stay on the current page. The information posted to the header is the "name" of each input/select etc which equals the value of the relevant input field. E.g. <input type="text" name="hello">World</input> [code] This will post variables to the header which look like ?hello=world in its raw format. This is then put into your $_POST variable as $_POST = array("hello" => "World"). The same principle applies for select tags. The value specified in your option tag is the value posted to the header. If you want to use IDs you need a table in your database which defines what the IDs link to. I assume this is already done as you retrieve the information as you progress through your drop downs.
  17. Your going about that in a very long winded way class languages { public function __construct() { $_SESSION['language'] = (isset($_GET['lang']) && in_array($_GET['lang'], array('en', 'nl') ? $_GET['lang'] : "DEFAULT LANGUAGE"); } } And ensure you check what the previous posts mentions...
  18. Through the use of sessions or by passing the information through the header...
  19. Be sure you don't want any data in the specified table as TRUNCATE will remove all the data... It's not a simple function to reset the auto-increment value to 0.
  20. Its a pointless idea unless you can somehow detect the submission of the review. This can only be done with either JS or by accessing the data through an API like the one in my previous post... All the frame would do is keep them on your website so you can control (to a certain degree) where they are.
  21. http://developer.yahoo.com/local/ First thing I searched came up with this... it's not hard. Although, not 100% how useful it'll be.
  22. cpd

    array spliting

    You can't. Array keys must be unique therefore you can only have one 15.jpg. What I suggest you do is have a multidimensional array. [1.jpg] => array([0] => "Callum", [1] => "Grant") [2.jpg] => array([0] => "Something", [1] => "Else", [2] => "Here")
×
×
  • 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.