I am getting an POST 500 (Internal Server Error) on my website.
When testing on my local host i get no errors, only after publishing and running the site live do I get errors when trying to add product into cart.
In shop php file I have written ajax code for adding item into cart and passing data through ajax into action file for SQL query and this is working fine in localhost server but I'm getting error in live website. Please show me way how can I overcome this problem.
This is my ajax code:
<script type="text/JavaScript">
$(document).ready(function(){
$(".addItemBtn").click(function(e){
e.preventDefault();
var $form =$(this).closest(".form-submit");
var pid=$form.find(".pid").val();
var pname=$form.find(".pname").val();
var pprice=$form.find(".pprice").val();
var pimage=$form.find(".pimage").val();
var pcode=$form.find(".pcode").val();
$.ajax({
url: 'action.php',
method: 'get',
data: {pid:pid,pname:pname,pprice:pprice,pimage:pimage,pcode:pcode},
success:function(response)
{
$("#message").html(response);
load_cart_item_number();
}
});
});
load_cart_item_number();
function load_cart_item_number()
{ $.ajax({
url: 'action.php',
method: 'get',
data: {cartItem:"cart_item"},
success:function(response){
$("#cart-item").html(response);
}
});
}
});
</script>
here is my second file action.php
if (isset($_GET['pid'])) {
$pid=$_GET['pid'];
$pname=$_GET['pname'];
$pprice=$_GET['pprice'];
$pimage=$_GET['pimage'];
$pcode=$_GET['pcode'];
$userid= $_SESSION["id"];
$pqty=1;
$sql = "SELECT product_id FROM cart WHERE user_id=$userid and product_id = ?";
$stmt = mysqli_prepare($link, $sql);
mysqli_stmt_bind_param($stmt, "s", $pcode);
mysqli_stmt_execute($stmt);
$res=$stmt->get_result();
$row=$res->fetch_assoc();
$code=$row['product_id'];
if(!$code)
{
$query="INSERT INTO `cart`(`user_id`,`product_name`, `product_price`, `product_image`, `qty`, `total_price`, `product_id`) VALUES (?,?,?,?,?,?,?)";
$stmt = mysqli_prepare($link, $query);
mysqli_stmt_bind_param($stmt, "isisiii",$userid,$pname, $pprice,$pimage,$pqty,$pprice,$pcode);
mysqli_stmt_execute($stmt);
echo "Added to Buy Card";
}
else{
echo "Already Added In Buy Card";
}
}
Inside your server there might be some issues. Find and try to solve that. Your browser error log is disabled. To enable and show error in browser you should use below code //travel insurance calculator customization
If you don't enable error to show in browser. then see your error log file in your base directory inside server. file name should be error.log or something else