I have a while loop statement to echo some information from the database. every loop has a button. When I click on that button i want to send 2 value's and have an update function with those 2 value. So far I have been getting only 1. The other one is blank. I want to get the id's via javascript or normal href="" this is my while loop
while ($row = mysqli_fetch_array($query)){
$productimg = $row["Product_Image"];
$productname = $row["Product_Name"];
$price = $row["Product_Price"];
$quantity = $row["Quantity"];
$seller = $row["Product_Seller"];
$cartid = $row["Cart_ID"];
$newimg = str_replace(' ', '%20', $productimg);
echo "<div class='cartcontent'>";
echo "<div class='s1'><a href='itemview.php?ID=$productname'><img src=$newimg /></a></div>";
echo "<div class='s2'><div class='s2t'><a href='itemview.php?ID=$productname'>$productname </a> <h2>Sold By $seller</h2></div><div class='s2b'><a href='?deletecartid=$cartid'>Delete</a> <a href='?saveforlaterid=$cartid'>Save for later</a></div></div>";
echo "<div class='s3'>$price</div>";
echo "<div class='s4'>";
include 'itemquantity.php';//this page class="qty2"
echo " <a href='?updateid=$cartid?quant=".$_GET['qty2']."'>Update</a>";//this is what i am struggling with
echo "</div></div>";
echo "?updateid=$cartid?quant=".$_GET['test']."";//just to see what i am getting
$count++;
}
I even tried getting a value from javascript for the onchange method from the dropdownlist inside the itemquantity.php which its class is qty2.
function getquant(){
var e = document.getElementsByClassName("qty2")[0];
var qty = e.options[e.selectedIndex].value;
alert(qty);
document.getElementById("test").innerHTML = qty;
};
And this is the isset get function
if(isset($_GET['updateid'])){
$updateid = $_GET['updateid'];
$updatequant = $_GET['quant'];
$query = mysqli_query($conn, "UPDATE cart SET Quantity = '$updatequant' WHERE Cart_ID = '$updateid'");}
I've seen some info's around about XMLhtml and cookie but they somewhat did not work so I have no idea what else to do lol.
If anyone knows how or has a working method, would be appreciated!
EDIT: Just to clarify the $_GET['qty2'] is inside the itemquantity.php(which is included in my while loop) it is a dropdownlist. this is what itemquantity.php looks like
<select placeholder='quantity' class='qty2' id='qty2' onchange="getquant()" value='<?php print_r($cartid);?>'>
<option value='1' <?php if ($quantity == '1') echo ' selected="selected"'; ?>>1</option>
<option value='2' <?php if ($quantity == '2') echo ' selected="selected"'; ?>>2</option>
<option value='3' <?php if ($quantity == '3') echo ' selected="selected"'; ?>>3</option>
<option value='4' <?php if ($quantity == '4') echo ' selected="selected"'; ?>>4</option>
<option value='5' <?php if ($quantity == '5') echo ' selected="selected"'; ?>>5</option>
<option value='6' <?php if ($quantity == '6') echo ' selected="selected"'; ?>>6</option>
<option value='7' <?php if ($quantity == '7') echo ' selected="selected"'; ?>>7</option>
<option value='8' <?php if ($quantity == '8') echo ' selected="selected"'; ?>>8</option>
<option value='9' <?php if ($quantity == '9') echo ' selected="selected"'; ?>>9</option>
the dropdown list is in a get method with class='qty2' id='qty2' onchange="getquant()" value='
By stopping the PHP parser before putting in static HTML you can more easily solve this problem.
Here's how you should have written the code for the loop
while ($row = mysqli_fetch_array($query)){
$productimg = $row["Product_Image"];
$productname = $row["Product_Name"];
$price = $row["Product_Price"];
$quantity = $row["Quantity"];
$seller = $row["Product_Seller"];
$cartid = $row["Cart_ID"];
$newimg = str_replace(' ', '%20', $productimg);
// end PHP processor
?>
<div class='cartcontent'>
<div class='s1'><a href='itemview.php?ID=<?php print_r($productname);?>'>
<img src='<?php print_r($newimg);?>' /></a></div>
etc etc.
<?php
// now start the PHP processor again and finish out the loop
$count++;
}
the problem with the line containing this:
<a href='?updateid=$cartid?quant=".$_GET['qty2']."'>Update</a>
is that your doing ?updateid=$cartid?quant=
which should be
?updateid=$cartid&quant=
multiple query values should be separated with an &
, as the ?
only belongs at the beginning of a query string