I am getting this error on hostgator Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 64 bytes)
but its working perfect on bluehost
I do have access to php.ini and memory limit is already set to 64 memory_limit = 64M;
I am unable to figure it out that wht is it so, please help.
I don't know which part of code is generating error, but I am providing all of it.
config.php
<?php
$currency = '$'; //Currency sumbol or code
$db_username = 'root';
$db_password = '';
$db_name = 'educators';
$db_host = 'localhost';
$mysqli = new mysqli($db_host, $db_username, $db_password,$db_name);
?>
cart.php
<div class="shopping-cart">
<h2>Your Cart</h2>
<?php
if(isset($_SESSION["courses"]))
{
$total = 0;
echo '<ol>';
foreach ($_SESSION["courses"] as $cart_itm)
{
echo '<li class="cart-itm">';
echo '<span class="remove-itm"><a href="cart_update.php?removep='.$cart_itm["id"].'&return_url='.$current_url.'">×</a></span>';
echo '<h3>'.$cart_itm["title"].'</h3>';
echo '<form action="cart_update.php" method="post">
<div>No. of Participants : <input name="qty" class="qty" type="text" value="'.$cart_itm["qty"].'" />
<input type="hidden" name="course_id" value="'.$cart_itm["id"].'" />
<input type="hidden" name="return_url" value="'.$current_url.'" />
<input class="update" name="update" type="submit" value="Update" />
</div>
</form>';
echo '<div>Price :'.$currency.$cart_itm["fee"].', Subtotal: '.$currency.$cart_itm["fee"]*$cart_itm["qty"].'</div>';
echo '</li>';
$subtotal = ($cart_itm["fee"]*$cart_itm["qty"]);
$total = ($total + $subtotal);
}
echo '</ol>';
echo '<span class="check-out-txt">Total : '.$currency.$total.'</span> <a class="checkout" href="view-cart.php">Next</a> <br class="clear" />';
}else{
echo 'Your Cart is empty';
}
?>
</div>
cart_update.php
<?php
include_once("config-cart.php");
//add item in shopping cart
if(isset($_POST["type"]) && $_POST["type"]=='add')
{
$id = filter_var($_POST["id"], FILTER_SANITIZE_STRING); //course code
$return_url = $_POST["return_url"]; //return url
//MySqli query - get details of course from db using course code
$results = $mysqli->query("SELECT title,fee FROM courses WHERE id='$id' LIMIT 1");
$obj = $results->fetch_object();
if ($results) { //we have the courses info
//prepare array for the session variable
$new_courses = array(array('title'=>$obj->title, 'id'=>$id, 'qty'=>1, 'fee'=>$obj->fee));
if(isset($_SESSION["courses"])) //if we have the session
{
$found = false; //set found item to false
foreach ($_SESSION["courses"] as $cart_itm) //loop through session array
{
if($cart_itm["id"] == $id){ //the item exist in array
$qty = $cart_itm["qty"]+1; //increase the quantity
$courses[] = array('title'=>$cart_itm["title"], 'id'=>$cart_itm["id"], 'qty'=>$qty, 'fee'=>$cart_itm["fee"]);
$found = true;
}else{
//item doesn't exist in the list, just retrive old info and prepare array for session var
$courses[] = array('title'=>$cart_itm["title"], 'id'=>$cart_itm["id"], 'qty'=>$cart_itm["qty"], 'fee'=>$cart_itm["fee"]);
}
}
if($found == false) //we didn't find item in array
{
//add new user item in array
$_SESSION["courses"] = array_merge($courses, $new_courses);
}else{
//found user item in array list, and increased the quantity
$_SESSION["courses"] = $courses;
}
}else{
//create a new session var if does not exist
$_SESSION["courses"] = $new_courses;
}
}
//redirect back to original page
header('Location:'.$return_url);
}
//remove item from shopping cart
if(isset($_GET["removep"]) && isset($_GET["return_url"]) && isset($_SESSION["courses"]))
{
$id = $_GET["removep"]; //get the courses code to remove
$return_url = $_GET["return_url"]; //get return url
foreach ($_SESSION["courses"] as $cart_itm) //loop through session array var
{
if($cart_itm["id"]==$id){ //item exist in the list
//continue only if quantity is more than 1
//removing item that has 0 qty
if($cart_itm["qty"]>1)
{
$qty = $cart_itm["qty"]*0; //just decrese the quantity from -1 to *0
//prepare array for the coursess session
//$courses[] = array('title'=>$cart_itm["title"], 'id'=>$cart_itm["id"], 'qty'=>$qty, 'fee'=>$cart_itm["fee"]);
}
}else{
$courses[] = array('title'=>$cart_itm["title"], 'id'=>$cart_itm["id"], 'qty'=>$cart_itm["qty"], 'fee'=>$cart_itm["fee"]);
}
//set session with new array values
$_SESSION["courses"] = $courses;
}
//redirect back to original page
header('Location:'.$return_url);
}
//remove item from shopping cart
if(isset($_POST["update"]) && isset($_SESSION["courses"]))
{
$id = $_POST["course_id"]; //get the courses code to remove
$return_url = $_POST["return_url"]; //get return url
foreach ($_SESSION["courses"] as $cart_itm) //loop through session array var
{
if($cart_itm["id"]==$id){ //item exist in the list
//continue only if quantity is more than 1
//removing item that has 0 qty
if($cart_itm["qty"]>=1 && $_POST['qty']>=1)
{
$qty = $_POST['qty']; //just change the quantity from 1 to qty post
//prepare array for the coursess session
$courses[] = array('title'=>$cart_itm["title"], 'id'=>$cart_itm["id"], 'qty'=>$qty, 'fee'=>$cart_itm["fee"]);
}
if($cart_itm["qty"]>=1 && $_POST['qty']=0)
{
$qty = $qty = $cart_itm["qty"]*0; //just change the quantity from 1 to qty post
//prepare array for the coursess session
//$courses[] = array('title'=>$cart_itm["title"], 'id'=>$cart_itm["id"], 'qty'=>$qty, 'fee'=>$cart_itm["fee"]);
}
}else{
$courses[] = array('title'=>$cart_itm["title"], 'id'=>$cart_itm["id"], 'qty'=>$cart_itm["qty"], 'fee'=>$cart_itm["fee"]);
}
//set session with new array values
$_SESSION["courses"] = $courses;
}
//redirect back to original page
header('Location:'.$return_url);
}
?>