Jump to content

Pavlos1316

Members
  • Posts

    302
  • Joined

  • Last visited

Everything posted by Pavlos1316

  1. Hello, Thank you for the example. I cannot test it right now, but I am reading it in order to understand the most of it. What you say "DO NOT CHANGE" I didn't understand much, especially from the first half, but at the end I think it's checking the str if it's null or not and displays it. AS for the js/formprocessing.js I get the most of it since is validating the form objects. What I cannot understand what exactly it says/does is: str = str.substr(0,(str.length - 1)); From 01ajax_process.php there is nothing really to understand since the whole script is straight forward. Correct? Now since I cannot test it, I cannot see if it's working without refreshing the page Is it the part that I didn't quite understand that does the trick??? So to start also understand on how I should change my code: 1. You are replacing my <form action="cart_functions.php"> with onClick="sendRequest(this.form, '01ajax_process.php'). Are these two way different or either one is ok? Do they behave different? 2. My file cart_functions.php will replace 01ajax_process.php. Right? And most important: 3... The js/formprocessing.js I have to find the right way to modified it and include it in my scripts in order to get what I want. Correct? In there you are telling to str to be displayed inside a <div>. My cart will be already displayed when I will be calling this JS file. Should I assign it to use the current <div> by just replacing the div's name in your code or do I have to change something else as well?
  2. Hello all, Everybody said I have to go with ajax, so here I am I don't know much about AJAX so... any help will be welcomed. I am trying to update my cart without refreshing my page. For updading my quantity I use: <form name="upd_itm" id="upd_itm" action="cart.functions.php" method="post"> <span class="text"> <input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" style="text-align: center;"/> <br /> <button name="adjustBtn' . $item_id . '" id="adjustBtn' . $item_id . '" type="submit" class="avoid_ref" value=""><img src="bttn_pics/change_value.png" /></button> <input name="item_to_adjust" id="item_to_adjust" type="hidden" value="' . $item_id . '" /> </span> </form> and a similar code to delete item from cart. It is working but only if I refresh the page I get to see the results. Any hint or script example on how I can modify it in order to work? I tried to understand and use this, but with no luck (I don't even know if this is correct): var request = $.ajax({ var keyValues = { pid : $(this).parent().find('input[name="pid"]').val(), item_to_adjust : $(this).parent().find('input[name="item_to_adjust"]').val(), index_to_remove : $(this).parent().find('input[name="index_to_remove"]').val(), recycleCart : $(this).parent().find('input[name="recycleCart"]').val() }; url: 'cart_functions.php', data: 'keyValues', type: 'post', dataType: 'html' }); request.success(function(response, textStatus, jqXHR) { // in here, response is what was returned by PHP return false; }); request.error(function(jqXHR, textStatus, errorThrown) { // in here, you can get detailed information on why the request would have failed }); Thank you in advance
  3. Hello, dragon_sa, I already submit my form successfully. I just want to make my image to appear like clicking a button when it's clicked and not be just a static image. Right now I am testing the button tag with some css styling: <button class="bttnlike"><img src="" /></button> //css .bttnlike{ background-color: transparent; border: none; } and I think is working... will see.
  4. Is there a way to make an img button to act/behave like type="submit" at the appearance part? I mean when you click it to see that you are clicking a button and not a static image. Thank you
  5. And this is why I cannot use <?php echo ?> again, because I am already using both of them. Correct?
  6. This I didn't pay much attention because it was doing nothing and it didn't displayed in my page. I was just trying some things in order to get something else to work. I've shown all I have. As it is my code e.g. with: <span class=itmttl>' . $product_name . '</span> I get the product name displayed, but if I replace it with: <?php echo $product_name; ?> I get <?php echo $product_name; ?> displayed. Now if you are asking how am I calling my dynamicList, I do it in another page using: <?php echo "$dynamicListBody"; ?> inside my <body> tags.
  7. Sorry, it is a typo... I have the ";" ending
  8. Hello, Below is a part of my dynamicList which I use to list some items: <?php // I connect to my db here $sql = mysql_query("SELECT * FROM items WHERE category='a' ORDER BY id ASC"); $productCount = mysql_num_rows($sql); if ($productCount > 0) { $i=0; $dynamicListBody = '<?php session_start(); ?><table width: 90%; margin-right: auto; margin-left: auto; color: #00E6AA;>'; while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $product_name = $row["product_name"]; $dynamicListBody .= ($i==0) ? '<tr>':''; $dynamicListBody .= '<td width="10%"> <div align="center"> <img style="border:#666 1px solid;" src="../stock_photos/' . $id . '.png" height="80px" width="40px" alt="' . $product_name . '" /> </div> </td> <td width="35%"> <div align="center"> <span class=itmttl>' . $product_name . '</span> </div> </td>'; $dynamicListBody .= ($i==1) ? '</tr>':''; $i++; ($i==2) ? $i=0:''; } $dynamicListBody .='</table>'; } else { $dynamicListBody = "We have no items"; } ?> This is working perfect, but if I want to replace this: ' . $variable . ' with this: <?php echo $variable; ?> is not working. What is wrong here Thank you
  9. ok... I found an other code which I was playing with some time ago. I tried it and it's partialy work with my dynamicList like this: dynaList (the form part): <form name="bd_itm" id="bd_itm" method="post" action="p_cart1.php?action=add&id=' . $id . '"> <input type="hidden" name="pid" id="pid" value="' . $id . '" /> <input type="submit" name="button" id="button" value="Add to Cart" /> </form> And the cart-functions.php: $cart = $_SESSION['cart']; $action = $_GET['action']; switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; //case 'update': //case 'delete': I now for sure that it is getting the $id and sends it to the cart.php (it has some othere problems but I don't want to get into that). My question is, how can I join the (only the case 'add' I need): $cart = $_SESSION['cart']; $action = $_GET['action']; switch ($action) { case 'add': //MY add code that I will post below } with my add-to-cart code (and most likely make it work): if (isset($_POST['pid'])) { $pid = $_POST['pid']; $wasFound = false; $i = 0; // If the cart session variable is not set or cart array is empty if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) { // RUN IF THE CART IS EMPTY OR NOT SET $_SESSION["cart_array"] = array(0 => array("item_id" => $pid, "quantity" => 1)); } else { // RUN IF THE CART HAS AT LEAST ONE ITEM IN IT foreach ($_SESSION["cart_array"] as $each_item) { $i++; foreach($array as $key => $value) { if ($key == "item_id" && $value == $pid) { // That item is in cart already so let's adjust its quantity using array_splice() array_splice($_SESSION["cart_array"], $i-1, 1, array(array("item_id" => $pid, "quantity" => $each_item['quantity'] + 1))); $wasFound = true; } // close if condition } // close while loop } // close foreach loop if ($wasFound == false) { array_push($_SESSION["cart_array"], array("item_id" => $pid, "quantity" => 1)); } } exit(); } Thank you
  10. Hello, I have just tested your code. I get displayed only: a) A Button valued "Clear Cart" and at the next line b) A "Clear Cart" link. Nothing else
  11. Hello, I will give it a try again with your code. Is there a way to use the fix you suggest with my add-remove-update functions? Is there a reason that my code doesn't get proccessed?? Thank you
  12. Drummin you re talking like I have solved this... but I haven't... I have been playing around and these are my results: ok... I will try my best to explain this. 1. all my cart-functions.php (add-show-remove) <?php //Add header("location: ../cart.php"); exit(); //Show-Remove ?> 2. my dynamicList.php <?php //Show the list <form name="bd_itm" id="bd_itm" method="post" action="help_scripts/cart-functions.php"> <input type="hidden" name="pid" id="pid" value="' . $id . '" /> <input type="submit" name="button" id="button' . $id . '" value="Add to Cart" /> ?> Here is what happening (i am testing in FireFox using Fire Bug) If I click my <Add to Cart> button FB shows that my pid=is unique for each item and I know that is has sent it into my cart-functions.php because it shows also the cart.php that I am sending it to. BUT NO ITEM IS ADDED TO MY CART No errors Anywhere! I am using this code to display errors <?php error_reporting(E_ALL); ini_set("display_errors", 1); ?> If I add my session_start(); inside my cart-functions.php at the top (I have it in my index.php for now), the first item of my dynaList is added in my cart. But ONLY the first! Is there the possibility to be a bug with dynamiclist not understanting that session is started and ignoring my <add.to.cart.script>? Or is it just something that no-one has understand yet in order to help me fixing it????? Thank you
  13. Oh... It's 01:15... In 5 hours I have to wake up... Good Night... for tonight
  14. yes... I don't want to be redirected or refreshed.... But that I managed... The major problem, I think thats why I started this post (I can't remember anymore), it was because my add-to-cart function wasn't proccessing any other item but the first. And the suggestion was to get unique values for my items and keys...! Even that I have just discovered using the firebug, that my pid is getting unique every time...! This isn't what you are trying to do and help me with your scripts???
  15. ok... I tested it several times... I had to comment out some of my jquery script in order not to block your php, but the only thing I get to display is the clear button..... I have different external script pages for dynamicList.php and my cart-functions.php to add-remove-update the cart. I was "blocking" the redirection to the cart with jq. Now even without the jq, letting the add button to redirect me, I don't get the items displayed... Only the Clear Cart Button....
  16. Hello Drummin, I haven't test what you gave me still but I just wanted to say: Thank you. P.S. I had all the lines of the code as you were asking me to... Don't worry, at least I got that right But I have all my scripts on external files. even the ones that you were giving me. I hope that wasn't the problem. Going to test what you wrote now....
  17. .... hmmm... No. I Don't want to do anything, but just adding an item and staying at my items page. That's why I tried to change the code a little bit. Else I would just copy paste the entire code as it was and finished (it was working as it was). I just said to mention it in case that it would make it easier to fix my code. I cannot even make your code to work and I cannot think why since you tried it and is ok. As for my last question.... Are they exactly the same? Thank you
  18. Hello, I am watching again the tutorial that I used for my cart. In the tutorial the author is using the dynaList to create items like that: item 1 | price | View item details (which is a link to the item's page) Now, that page with only the item 1 details in it, has the "Add to Cart" Button. What I haven't realize when I was changing it in order to include the Add to Cart Button inside the dynaList is the way that the author was sending the user to the single product page. The "View item details" link was <a href="product.php?id=' . $id . '">View item details</a> and after in the product page is getting that id with: if (isset($_GET['id'])) { // Connect to the MySQL database include "scripts/connect_to_mysql.php"; $id = preg_replace('#[^0-9]#i', '', $_GET['id']); and continues by getting all the info to display that product and adding it to the cart (with the code and keys that I am using) without any problem. What is changing in my dynaList and is not working compared to the above? Another tip that I want: Is it value="' . $id . '" exactly the same as value="<?php echo $id; ?>" ?
  19. Always... I have that also... Anyway... Where I am is 1 oclock in the morning and tomorrow is a working day Have a good night. Thank you P.S. To be continued... For me at least :)
  20. // check for errors require_once('check_all_errors.php'); I got rid of this... no more errors but a new page is displayed eith only clear cart inside. No items, no quantity.
  21. I did all the cleanups and the for as you suggested... I am rechecking, but.....
  22. And your item list is created as mine (dynamic)?
  23. yes I tried but I had undifined index error.... Undefined index: button Undefined index: end Undefined varianle: i
  24. Yes... they are my keys and you told me that they should get unique name because this is the problem.
×
×
  • 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.