Form action not working properly.

Hey guys, I am trying to make a little shopping cart web app for a course and I am having a bit of a problem. It only started happening when I added lots of html/css, but the php code is the same.

I have a form:
[php]
echo ‘’;
echo ’ Quantity:&nbsp

’;
echo ‘<input type=“hidden” name=“hiddenSKU value=”’.$rec[‘SKU’].’">’;
echo ‘
’;
[/php]

Where a user will submit a quantity and add it to the cart.
The product_handler.php is:
[php]

<?php session_start(); $dbConn = new mysqli("localhost","root","","store"); $result = $dbConn->query("INSERT INTO cart VALUES('".session_id()."',now(),".$_POST['qty'].",".$_POST['hiddenSKU'].");"); $dbConn->close(); header('location:http://localhost/final2/index.php'); ?>[/php]

(the $result is all one line in the source, changed it here for better formatting)

My ‘cart’ table is not updating in the way that I thought it would, am I missing something obvious? Thanks for your help.

Done and tested,
You missed single quotes before and after $_POST,
replace this line,

[php]$result = $dbConn->query(“INSERT INTO cart VALUES(’”.session_id()."’,now(),’".$_POST[‘qty’]."’,’".$_POST[‘hiddenSKU’]."’);");[/php]

Awesome, thank you! I can’t believe I missed that because I had the same issue in two other files yesterday. Guess it’s time for a break.

Thanks again.

Sponsor our Newsletter | Privacy Policy | Terms of Service