Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,450
  • Joined

  • Days Won

    175

Everything posted by mac_gyver

  1. nested forms are invalid. you need to fix that before you can fix anything else your code might be doing. to help yourself and anyone else you might be asking to help you, you should also elimiate all the commneted out code and since you are creating a database connection in the functions.php file, elimiate the variables and connections you also creating in the individual files.
  2. and in which file? i've looked at some of the code more and you have nested form tags that are invalid. the first opening form tag is what will be submitted to, so I don't even think your form is submitting to the file you think it is. you need to clean up all your code and validate the resulting html. there's problems with form tags and table tr/td tags. i also see one = sign in an if() test that is assiging a value instead of comparing a value.
  3. the symptom is that of a variable being reused. since you have posted a book-load of double-spaced code, it would help if you identified which variable name you are var_dump'ing and in which piece of code it is to pin down where to even start looking. without knowing which variable you are talking about, the only apparent problem is you have an extra </form> tag at the end of the select_issue.php code file that is messing with all the forms being output in that file.
  4. code snippets that implement the suggestions - <?php session_start(); // simple form process controller - $action = isset($_POST['action']) ? $_POST['action'] : ''; switch($action){ case 'add': // add/increment item to cart (quantity one) // inputs: 'add to cart' flag, item id // processing: add new or increment existing item id in the cart $id = (int)$_POST['id']; if($id > 0){ // valid submitted id if(!isset($_SESSION['item'][$id])){ // not already in cart $_SESSION['item'][$id] = 0; // create entry } $_SESSION['item'][$id]++; // increment quantity } break; case 'delete': // delete item from cart // inputs: 'delete from cart' flag, item id // processing: remove item id entry from the cart $id = (int)$_POST['id']; if($id > 0){ // valid submitted id unset($_SESSION['item'][$id]); } break; } // display the cart if(empty($_SESSION['item'])){ echo "Your cart is empty!<br>"; } else { echo "Your cart has ".array_sum($_SESSION['item'])." item(s) in it.<br>"; // get the item ids from the cart $ids = implode(',',array_keys($_SESSION['item'])); echo "ids are: $ids<br>"; // code to get and display the product infomration for the list of ids is left as a programming exercise } // display what's going on echo '<pre>','cart:',print_r($_SESSION,true),'post:',print_r($_POST,true),'</pre>'; ?> Add some items -<br> id: 123<form method='post' action=''> <input type='hidden' name='action' value='add'> <input type='hidden' name='id' value='123'> <input type='submit' value='Add to cart'> </form> id: 456<form method='post' action=''> <input type='hidden' name='action' value='add'> <input type='hidden' name='id' value='456'> <input type='submit' value='Add to cart'> </form> Delete some items -<br> id: 123<form method='post' action=''> <input type='hidden' name='action' value='delete'> <input type='hidden' name='id' value='123'> <input type='submit' value='Remove from cart'> </form> id: 456<form method='post' action=''> <input type='hidden' name='action' value='delete'> <input type='hidden' name='id' value='456'> <input type='submit' value='Remove from cart'> </form>
  5. this is just my opinion, but the defintion of your cart is resulting in extra code and data, and even results in security problems because you are passing unneeded data through the form that must be validated once it reaches the server. your cart should use the item id from the product database as the first level key and the only real data you need to store in the cart for each item is the quantity. the only thing the add to cart form needs to submit is the item id and a quantity (assuming you want to allow more than one of anything to be bought.) to delete the item from the cart, just use the item id to unset it like you are doing now. there's no need to move or renumber the indexes. what's with the $_SESSION['count_cart']? you can just use the php array count() function to get a count of the items in the cart at any time or if you are storing a quantity of each item, use array_sum(). no need for any extra code to set the count_cart variable or to increment and decerment it. to display the cart, just get all the item ids out of the cart and use them to fetch the display information from the database.
  6. you must be escaping the actual query statement insted of just the data going into the query statement. the syntax of the query, quotes and such that you add around the data to produce the query, don't get escaped.
  7. this is a chicken and egg age problem. the age value is calculated in the select term for the rows that have been selected. the where term determines which rows to select. the easiest, not fastest, way would be to use a HAVING age BETWEEN 30 AND 40 term. the fastest way would be to put the calculation into the WHERE term.
  8. the mysqi extension that is listed in the phpMyAdmin output is just the extension that phpMyAdmin is using to connect to the database server. in order to profile your application to find out where the problem lies, it would be ncessary to know everything your appliction is doing. nothing can be told from a few snippetts of code.
  9. your load time is slow because doing this all client side requires all the data to be sent to the client. to do what you ask would require that you use ajax to submit the selected filter to the server and the server just returns the selected product data. look at some ajax examples for your appliction.
  10. or you can pass the selected search filters in the url so that someone can create a bookmark or shortcut to the page and return to the same point later or share the search result with someone else via a link.
  11. apache and iis are both web servers. you can use either one. unless you are doing something that requires iis, there's no good reason to mess around trying to install php under iis. you will probably get more uptodate installation help if using apache. you can also use one of the allinone win/apache/php packages if your goal is to just get php running as easy as possible on a computer. you don't need to install the mysql server if you don't want or need it. afaik, for iis, you should install php as a fastcgi app. there are current installation instructions in the php.net manual. you would use php-cgi.exe. php.exe is the command line intrepeter.
×
×
  • 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.