Open
Description
I am trying to get simpleCart to send variables to a database.
I have tried almost everything but it comes with an error
PHP Notice: Undefined index: itemCount in E:\inetpub\gadekoekkenet_umbraco\php\order.php on line 34
if I use print_r ($_POST); I get an empty array so it looks like it doesn't get the data from the cart.
This is my php-file so I hope someone can help me in the right direction.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content=" " />
<meta name="author" content=" " />
<meta name="HandheldFriendly" content="true" />
<meta name="MobileOptimized" content="320" />
<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" href="../css/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="../scripts/simpleCart.js"></script>
</head>
<body>
<h1>Hello, World!</h1>
<p>Go ahead and add your content!</p>
jgjgj
<?php print_r(PDO::getAvailableDrivers()); ?>
<?php include('connect-db.php'); ?>
<form name="input" action="" method="post">
<div class="simpleCart_items"></div>
KundeNavn: <input type="text" name="KundeNavn"><br>
KundeAdresse: <input type="text" name="KundeAdresse"><br>
KundePostnummer: <input type="text" name="KundePostnummer" value=""> KundeBy:<input type="text" name="KundeBy"><br><br>
<?php
$content = $_POST;
for($i=1; $i < $content['itemCount'] + 1; $i++) {
$name = 'item_name_'.$i;
$quantity = 'item_quantity_'.$i;
$price = 'item_price_'.$i;
$total = $content[$quantity]*$content[$price];
} ?>
<input type="submit" value="Submit" name="Submit" onclick="simpleCart.checkout()">
</form>
<?php
if(isset($_POST['Submit'])){
$KundeNavn = $_POST['KundeNavn'];
$KundeAdresse = $_POST['KundeAdresse'];
$KundePostnummer = $_POST['KundePostnummer'];
$KundeBy = $_POST['KundeBy'];
$query = "INSERT INTO Ordre ([KundeNavn], [KundeAdresse], [KundePostnummer], [KundeBy], [MenuItem], [MenuQuantity], [MenuPrice], [MenuTotal]) VALUES('$KundeNavn', '$KundeAdresse', '$KundePostnummer', '$KundeBy', '$name', '$price', '$quantity', '$total' )";
$result = sqlsrv_query($conn, $query)or die('Error querying MSSQL database');
}
?>
<div class="">
<?php
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true));
}
$sql = "SELECT * FROM Ordre";
$stmt = sqlsrv_query( $conn, $sql );
if( $stmt === false) {
die( print_r( sqlsrv_errors(), true) );
}
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
echo "<table>";
echo "<tr>";
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['KundeNavn'] . '</td>';
echo '<td>' . $row['KundeAdresse'] . '</td>';
echo '<td>' . $row['KundePostnummer'] . '</td>';
echo '<td>' . $row['KundeBy'] . '</td>';
echo '<td>' . $row['MenuItem'] . '</td>';
echo '<td><a href="edit.php?id=' . $row['id'] . '">Edit</a></td>';
echo '<td><a href="delete.php?id=' . $row['id'] . '">Delete</a></td>';
echo "</tr>";
echo "</table>";
}
sqlsrv_free_stmt( $stmt);
?>
</div>
<h1>test</h1>
<?php
switch (PHP_INT_SIZE) {
case 4:
echo '32-bit version of PHP';
break;
case 8:
echo '64-bit version of PHP';
break;
default:
echo 'PHP_INT_SIZE is ' . PHP_INT_SIZE;
}?>
</body>
<!-- <script type="text/javascript">
$(".saveCart").click(function(){
$(".itemRow").each(function(){
var itemName = $(this).find(".item-name").text();
var itemPrice = $(this).find(".item-price").text();
var itemQty = $(this).find(".item-quantity").text();
var itemTotal = $(this).find(".item-total").text();
$.ajax({
// Enter below the full path to your "cart" php file
url: "../../order.php",
type: "POST",
data: {custId: custId, itemName: itemName, itemPrice: itemPrice, itemQty: itemQty, itemTotal: itemTotal},
cache: false,
success: function (html) {
// If form submission is successful
if ( html == 1 ) {
}
// Double check if maths question is correct
else {
}
}
});
});
});
</script> -->
<script>
simpleCart({
// array representing the format and columns of the cart,
// see the cart columns documentation
cartColumns: [
{ attr: "date", label: "Dato"},
{ attr: "name", label: "Ret"},
{ view: "decrement" , label: "" , text: "-" } ,
{ attr: "quantity", label: "Antal"},
{ view: "increment" , label: "" , text: "+" } ,
{ view:"currency", attr: "total", label: "DKK" },
{ view: "remove" , text: " " , label: "Fjern" }
],
// "div" or "table" - builds the cart as a table or collection of divs
cartStyle: "table",
// set the cart langauge (may be used for checkout)
language: "danish-dk",
checkout: {
type: "SendForm",
url: "../../order.php",
});
simpleCart.currency({
code:"DKK",
symbol:"",
name:"Danish Krone",
delimiter: " " ,
decimal: "," ,
accuracy: 2
});
// simpleCart.bind( 'beforeCheckout' , function( data ){
// data.first_name = document.getElementById("first_name").value;
// data.last_name = document.getElementById("last_name").value;
// data.email = document.getElementById("email").value;
// data.phone = document.getElementById("phone").value;
// data.comments = document.getElementById("comments").value;
// });
// example of modifying the price of the item based on a 'size' attribute
simpleCart.bind( 'beforeAdd' , function( item ){
if( item.get( 'size' ) == '1' ){
item.price( 48 );
} else if( item.get( 'size' ) == '2' ){
item.price( 55 );
}
});
</script>
</html>
I have tried to look at the #323 to get it to work but I can figure it out.
Don't mind the code it's only a test page....:)
Metadata
Metadata
Assignees
Labels
No labels