I’m trying to figure out how to convert my current shopping cart (hosted on Mal’s E-comm) into one which draws its “products” from a database.
This is the current html coding for one item (a dog show trophy donation):
<p>
<input type="checkbox" name="qty2" value="1"> Best Junior Showman Rosette - $30
<input type="hidden" name="product2[]" value="Best Junior Showman Rosette" />
<input type="hidden" name="price2" value="30" />
Dedication:
<input size="40" name="product2[]">
<input type="hidden" name="units2" value="1">
<input type="hidden" name="noqty2" value="1">
</p>
It looks like this on the page in a browser:
I found some coding on w3schools which I’ve copied and tweaked but I’m obviously doing something wrong. This is what I’ve come up with:
<?php
$servername = "";
$username = "*****";
$password = "*****";
$dbname = "*****";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT name, price, dedication FROM juniortrophies";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<p>
<input type='checkbox' name='qty7' value='1'>". $row["name"]. " - $". $row["price"].
"<input type='hidden' name='product7[]' value='". $row["name"]. "'/>
<input type='hidden' name='price7' value='". $row["price"]. "'/>
- Dedication: ". $row["dedication"].
"<input size='40' name='product7[]'>
<input type='hidden' name='units7' value='1'>
<input type='hidden' name='noqty7' value='1'>
</p>";
}
} else {
echo "0 results";
}
$conn->close();
?>
which results in the cart looking like this:
instead of like this:
It is displaying ALL the records in the cart instead of just the one required. Note that it also has the price wrong - it should be $20, not $40.
I’m guessing it’s misbehaving because one shouldn’t include the same value twice in one echo command but I need to have those values in there twice in order for the cart to work.
Does anyone have any idea about how to do this? I’ve read all the support articles on Mal’s website but unfortunately his user forum is down, so I can’t ask people who regularly use his carts. I’ve been using them for over 11 years and love them but now that I need to get a bit “fancier” I’m having this problem.
The reason I’m trying to do this (before someone asks ) is because currently when someone pays to donate for a particular trophy I have to manually open that html page and remove (or hide) that trophy so that nobody else can donate for it. The problem is, not everyone is in my time zone, so I’ve had 3 people donate for the exact same trophy while it was the middle of the night here.
I’d like to use Mal’s Remote Call feature to turn a Show_Hide field from ‘Y’ to ‘N’ so that the trophy with automatically disappear but in order to do that I’m pretty sure I need to bring in the trophy information from the DB.
Is this a pipedream on my part or can it really be accomplished?