Jump to content

rafal

Members
  • Posts

    37
  • Joined

  • Last visited

rafal's Achievements

Member

Member (2/5)

0

Reputation

  1. Dear Barand, thank you very much, you are great php expert i sent you email messege here in this forum, please answer. the code working now thank you again
  2. Hello Everybody, i have shopping-cart with session_product. i add arrays per button to the session. i want get the shipping1 and shipping2 fields from the array where the field qty great is or equal to 2 >= 2. i did this manualy in my example to get shi1 and shi2 lines 15 and 16. how can i get shipping1 and shipping2 automaticly? thank you very much for your help. here is my code 01.<?php 02.$maxshipping1=0; 03.foreach ($_SESSION['products'] as $pro1) { 04.$maxshipping1 = max($maxshipping1, $pro1['shipping1']); } 05.?> 06.<?php 07.$maxshipping2=0; 08.foreach ($_SESSION['products'] as $pro2) { 09.$maxshipping2 = max($maxshipping2, $pro2['shipping2']); } 10.?> 11.<?php 12.$maxqty=0; 13.foreach ($_SESSION['products'] as $quant) { 14.$maxqty = max($maxqty, $quant['qty']); } 15.$shi1 = $_SESSION["products"][0]["shipping1"]; 16.$shi2 = $_SESSION["products"][0]["shipping2"]; 17.?> the Arrays looks like the following: Array ( [0] => Array ( [product] => Orangensaft 0,3l [code] => 5 [qty] => 3 [price] => 2.99 [shipping1] => 5 [shipping2] => 7 ) [1] => Array ( [product] => Kuchen [code] => 3 [qty] => 1 [price] => 2.95 [shipping1] => 4 [shipping2] => 6 ) [2] => Array ( [product] => Burger 200g [code] => 4 [qty] => 1 [price] => 3.95 [shipping1] => 1 [shipping2] => 3 ) [3] => Array ( [product] => Pizza Pollo [code] => 2 [qty] => 1 [price] => 5.95 [shipping1] => 2 [shipping2] => 4 ) [4] => Array ( [product] => Sake Maki Lachs, 6 St�cke Pommes [code] => 4236134485469 [qty] => 1 [price] => 2 [shipping1] => 1 [shipping2] => 2 ) )
  3. thank you very much dear Barand, hansford and ginerjm now it works $maxshipping=0; foreach ($_SESSION['products'] as $prod) { $maxshipping = max($maxshipping, $prod['shipping1']); } echo $maxshipping;
  4. dear hansford, thank you very much for your help this is what i get from the session Array ( [0] => Array ( [product] => Orangensaft 0,3l [code] => 5 [qty] => 1 [price] => 2.99 [shipping1] => 4.9 [shipping2] => 6.9 ) [1] => Array ( [product] => Kuchen [code] => 3 [qty] => 1 [price] => 2.95 [shipping1] => 4 [shipping2] => 6 ) [2] => Array ( [product] => Burger 200g [code] => 4 [qty] => 1 [price] => 3.95 [shipping1] => 5.9 [shipping2] => 7.9 ) [3] => Array ( [product] => Pizza Pollo [code] => 2 [qty] => 1 [price] => 5.95 [shipping1] => 2 [shipping2] => 4 ) [4] => Array ( [product] => Sake Maki Lachs, 6 St�cke Pommes [code] => 4236134485469 [qty] => 1 [price] => 2 [shipping1] => 1 [shipping2] => 2 ) )
  5. this is the basket.php page. maybe it can help <?php session_start(); include("info.php"); if(isset($_GET["emptybasket"]) && $_GET["emptybasket"]==1) { $return_url = base64_decode($_GET["return_url"]); session_destroy(); header('Location:'.$return_url); } if(isset($_POST["type"]) && $_POST["type"]=='add') { $inventar = filter_var($_POST["inventar"], FILTER_SANITIZE_STRING); $product_qty = filter_var($_POST["product_qty"], FILTER_SANITIZE_NUMBER_INT); $return_url = base64_decode($_POST["return_url"]); if($product_qty > 1000){ die('Bestellung von mehr als 1000 Stück ist nicht möglich!'); } $query2="SELECT * FROM $table1 WHERE inventar='$inventar' LIMIT 1"; $result2 = $link1->query($query2) or die ("Database Error!"); $row = $result2->fetch_array(MYSQLI_ASSOC); if ($result2) { $new_product = array(array('product'=>$row[product], 'code'=>$inventar, 'qty'=>$product_qty, 'price'=>$row[price], 'shipping1'=>$row[shipping1], 'shipping2'=>$row[shipping2])); if(isset($_SESSION["products"])) { $found = false; foreach ($_SESSION["products"] as $cart_itm) { if($cart_itm["code"] == $inventar){ $product[] = array('product'=>$cart_itm["product"], 'code'=>$cart_itm["code"], 'qty'=>$product_qty, 'price'=>$cart_itm["price"], 'shipping1'=>$cart_itm["shipping1"], 'shipping2'=>$cart_itm["shipping2"]); $found = true; } else{ $product[] = array('product'=>$cart_itm["product"], 'code'=>$cart_itm["code"], 'qty'=>$cart_itm["qty"], 'price'=>$cart_itm["price"], 'shipping1'=>$cart_itm["shipping1"], 'shipping2'=>$cart_itm["shipping2"]); } } if($found == false) { $_SESSION["products"] = array_merge($product, $new_product); } else{ $_SESSION["products"] = $product; } } else{ $_SESSION["products"] = $new_product; } } header('Location:'.$return_url); } if(isset($_GET["removep"]) && isset($_GET["return_url"]) && isset($_SESSION["products"])) { $inventar = $_GET["removep"]; $return_url = base64_decode($_GET["return_url"]); foreach ($_SESSION["products"] as $cart_itm) { if($cart_itm["code"]!=$inventar){ $product[] = array('product'=>$cart_itm["product"], 'code'=>$cart_itm["code"], 'qty'=>$cart_itm["qty"], 'price'=>$cart_itm["price"], 'shipping1'=>$cart_itm["shipping1"], 'shipping2'=>$cart_itm["shipping2"]); } $_SESSION["products"] = $product; } header('Location:'.$return_url); } ?>
  6. Thank you dear hansford, i have removed the loop. when i write $shippall = $_SESSION["products"]["shipping1"]; i dont see any text same when i write $shippall = max($_SESSION["products"]["shipping1"]); i see number but not heighst value when i write $shippall = $cart_itm["shipping1"]; but if i add max() as the following, i dont see any number $shippall = max($cart_itm["shipping1"]);
  7. thank you very much dear Ginerjm and dear hansford, i want get the heighst value from the session key shipping1. now i changed the code to the following. $shippall = $cart_itm["shipping1"]; echo $shippall."<br>"; i see only one shipping1 value but not the heighst. when i change to echo MAX($shippall); i dont see anything more. i am very confused why i dont see heightst value!!!
  8. merry christmas everybody i have shopping basket, i put many items in it per session. i want get the heighst shipping1 value from session but i dont know how. i tryed last 3 day without success. now i get the following value for shipping1 2 3.90 5 6.90 but i see only 6.90 as it is the heighst shipping1 in basket. thank you very much for your help here is my code foreach ($_SESSION["products"] as $cart_itm) { $inventor = $cart_itm["code"]; $shippall = $cart_itm["shipping1"]; $query1 = "SELECT MAX(shipping1) FROM $table1 WHERE inventar='$inventor'"; $result1 = $link1->query($query1) or die ("Database Error!"); $row = mysqli_fetch_row($result1); echo $shippall."<br>"; }
  9. Hello Mikosiko, i do not understand your comment. Assignment Operator is not the same as the Comparison Operator. what is wrong and where?
  10. Hello Barand, when i try to enter duplicate of inventor, i get the error message "Database Error!" but not what i want "there is already product with same inventor id!". i think my "if" condition is wrong. am i right?
  11. dear Barand, the user can not insert product if there is inventor duplicate, my target is: i want show the user error message if he try to insert product with duplicate inventor. how to do this in the code? thanks Rafal
  12. Thanks Barand, i made already inventor as unique key in the mysql database. i dont want want update the price or product. i want make insert of duplicate inventor not possible. the user should get the following error message "there is already product with same inventor id!". thanks again Rafal
  13. Hello everybody, i try to check if the unique field inventar exists or not before i insert new record. if the inventar exits the user should get error message. but i dont know how to do this. thank you very much for your help. Rafal here is my code <?php include("123.php"); $inventar = $link1->real_escape_string($_POST["inp_inventar"]); $product = $link1->real_escape_string($_POST["inp_product"]); $price = $link1->real_escape_string($_POST["inp_price"]); $link1 = new mysqli("$hoster", "$nameuser", "$password", "$basedata") or die ("Connection Error!"); error_reporting (0); $check_inventar = mysqli_query($link1, "SELECT inventar FROM products WHERE inventar='$inventar'"); $check_inventar_num = mysqli_num_rows($check_inventar); if (isset($_POST['inp_submit']) AND $check_inventar_num = 0) { $query1 = "INSERT INTO products (inventar, product, price) VALUES ('$inventar', '$product', '$price')"; $result1 = $link1->query($query1) or die("Database Error!"); if ($result1 == true) { header ( 'Location:insert.php' ); } } else { echo "there is already product with same inventar id!"; } mysqli_close($link1); ?>
  14. Hello NotionCommotion, i made some changes and created database based login script. do i have security problems in this code? this is the code of index.php thanks Rafal <?php SESSION_START(); include("config.php"); $link1 = new mysqli("$hoster", "$nameuser", "$password", "$basedata") or die ("Connection Error!"); error_reporting (0); $email = $link1->real_escape_string($_POST["inp_email"]); $pwd = $link1->real_escape_string($_POST["inp_pwd"]); if($email && $pwd) { $chkuser = $link1->query("SELECT email FROM $table2 WHERE email = '$email' "); $chkuserare = mysqli_num_rows($chkuser); if ($chkuserare !=0) { $chkpwd = $link1->query("SELECT pwd FROM $table2 WHERE email = '$email' "); $pwddb = mysqli_fetch_assoc($chkpwd); if (hash('sha512', $pwd) != $pwddb["pwd"]) { echo "wrong password!"; } else { $_SESSION['username'] = $email; header ('Location:list.php'); } } else { echo "user not found!"; } } else { echo "enter your email and password!"; } mysqli_close($link1); ?> <html> <body> <form action="index.php" method="post"> <b>Login</b><br><br> <table width="100%"> <tr><td> Email:<br><input type="text" name="inp_email" style="width:98%; padding: 4px;"><br> Password:<br><input type="password" name="inp_pwd" style="width:98%; padding: 4px;"><br> <br> <input type="submit" name="submit" value="Login" style="width:100%; padding: 4px;"> </td></tr> </table> </form> </body> </html>
  15. Hello, i want to know if this code is ok or do i have sql-injection, session hijacking etc. thank you very much for your help. Rafal <?php INI_SET('SESSION.USE_ONLY_COOKIES', 1); SESSION_START(); SESSION_CACHE_EXPIRE(10); SESSION_REGENERATE_ID(); $uname = "mail@mail.com"; $upassword = "a4ca6e1f044a98a8a72e7b356a134319433f4d98adb3f463202246bddb883712459e66ea985f37cb2e7171165500c341be4effd1f6e4461246e3c61e5767741f"; if (isset($_POST["inp_name"]) && isset($_POST["inp_pwd"])) { if ($uname == $_POST["inp_name"] && $upassword == hash('sha512', $_POST["inp_pwd"])) { $_SESSION["e64X96ea"] = 1; } } ?> <?php if ($_SESSION["e64X96ea"] != 1) { header ( 'Location:login.php' ); exit; } ?>
×
×
  • 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.