I hope I'm not asking a question already answered, I have searched extensively on the site for an answer to my problem but can not manage to find a solution.
I have the following problem.
I have a form in which is a shopping cart, it is supposed to apply a coupon and then save those values so they can be used later on different pages.
For some reason however, these session variables are not saved.
My form looks like this:
<?php
session_start();
$cart_custom = json_decode($_COOKIE['view_cart_custom_fab'],true);
//print_r($cart_custom);
include_once("inc/header.php");
//set_add_to_cart_cookie();
$fetch_user_info = mysqli_query($conn,"SELECT * FROM `st_customer` WHERE `email`= '{$_SESSION['USER_EMAIL']}'");
$fetch_info = mysqli_fetch_array($fetch_user_info);
$size_id = ($_REQUEST['id'] ? $_REQUEST['id'] : $_COOKIE['fabric_size_id']);
$fabric_id = $_COOKIE['fabric_id'];
$fabric_back = $_COOKIE['fabric_back'];
$shirts = $_COOKIE['shirts'];
$fabric_arms = $_COOKIE['fabric_arms'];
$fabric_pocket = $_COOKIE['fabric_pocket'];
$fabric_cuff = $_COOKIE['fabric_cuff'];
$fabric_boy_border = $_COOKIE['fabric_boy_border'];
$fabric = mysqli_query($conn,"SELECT * FROM `st-fabrics` where `id` = '$fabric_id'");
$fabric_record = mysqli_fetch_array($fabric);
$fabric_back_data = mysqli_query($conn,"SELECT * FROM `st-fabrics` where `id` = '$fabric_back'");
$fabric_back_record = mysqli_fetch_array($fabric_back_data);
$arms = mysqli_query($conn,"SELECT * FROM `st-fabrics` where `id` = '$fabric_arms'");
$arms_record = mysqli_fetch_array($arms);
$pocket = mysqli_query($conn,"SELECT * FROM `st-fabrics` where `id` = '$fabric_pocket'");
$pocket_record = mysqli_fetch_array($pocket);
$cuff = mysqli_query($conn,"SELECT * FROM `st-fabrics` where `id` = '$fabric_cuff'");
$cuff_record = mysqli_fetch_array($cuff);
$border = mysqli_query($conn,"SELECT * FROM `st-fabrics` where `id` = '$fabric_boy_border'");
$border_record = mysqli_fetch_array($border);
$select_size = mysqli_query($conn,"SELECT * FROM `st_sizes` where `size_id` = '$size_id'");
$user_select_size = mysqli_fetch_array($select_size);
$model_id = $user_select_size['size_model'];
$model = mysqli_query($conn,"SELECT * FROM `st_model` where `model_id` = '$model_id'");
$model_name = mysqli_fetch_array($model);
if($shirts=="half_shirt"){
$shirt = $user_select_size['half_sleeve'];
}
if($shirts=="full_tshirt"){
$shirt = $user_select_size['full_sleeve'];
}
$cm1 = $fabric_record['fabric_price']/10;
$cm2 = $arms_record['fabric_price']/10;
$cm3 = $fabric_back_record['fabric_price']/10;
$front_size = ($cm1*$user_select_size['front']*100);
$back_size = ($cm3*$user_select_size['size_back']*100);
$arms_size = ($cm2*$shirt*100);
$front_back_total = $user_select_size['front']+$user_select_size['size_back'];
$custom_total = ($front_size+$back_size+$arms_size);
if(isset($_POST['apply_coupon_btn'])){
$query_coupon = mysqli_query($conn,"SELECT * FROM `st_coupon` WHERE `coupon_code`='{$_POST['coupon_apply']}' AND `status`='1'");
$fetch_coupon = mysqli_fetch_array($query_coupon);
$message = "tmp2";
if(isset($fetch_coupon)){
$_SESSION['coupon_data'] = $fetch_coupon;
$check_user_id = mysqli_query($conn,"SELECT * FROM `st_order` as so JOIN `st_coupon` as sc on so.`coupon_id`=sc.`coupon_id` WHERE sc.`coupon_code`='{$_POST['coupon_apply']}' AND so.`user_id`={$_SESSION['user_id']}");
$message = "tmp3";
if(mysqli_num_rows($check_user_id)){
$message = "U hebt deze kortingscode reeds gebruikt";
}else{
if($fetch_coupon['coupon_type'] == "price"){
$_SESSION['price_coupon_price'] = $fetch_coupon['coupon_value'];
unset($_SESSION['price_coupon_percent']);
}elseif($fetch_coupon['coupon_type'] == "percent"){
$_SESSION['price_coupon_percent'] = $fetch_coupon['coupon_value'];
unset($_SESSION['price_coupon_price']);
}
}
}else{
$message = "Foute kortingscode";
}
}
if(isset($_POST['remove_coupon_btn'])){
unset($_SESSION['price_coupon_percent']);
unset($_SESSION['price_coupon_price']);
unset($_SESSION['coupon_data']);
unset($_SESSION['price_coupon_value']);
header("location: winkelwagen.php");
}
if(isset($_POST['update_cart']))
{
echo "update cart";
foreach($_POST['custom_qty_cart'] as $key=>$qtys){
$cart_custom[$key]['price']['qty'] = $qtys;
}
setcookie('view_cart_custom_fab', json_encode($cart_custom), time() + (86400 * 2), "/");
setcookie('custom_qty', $_POST['custom_qty'], time() + (86400 * 2), "/");
$custom_total = $custom_total*$_POST['custom_qty'];
setcookie('custom', $custom_total, time() + (86400 * 2), "/");
foreach($_POST["qty"] as $key => $qty) { //Print each item, quantity and price.
$id = $_POST["product_id"][$key];
$_SESSION["products"][$id]["fabric_qty"] = $qty;
}
header("location: winkelwagen.php");
}
if(isset($_POST['checkout_btn'])){
if($_SESSION['USER_EMAIL']){
header("location: afrekenen.php");
}else{
header("location: winkelwagen.php#login-modelbox");
}
}
?>
<div class="container">
<h4><?php echo $_SESSION['price_coupon_value']; ?></h4>
<h4><?php echo $_SESSION['coupon_data']; ?></h4>
<div class="main_content fabric-content margin_top">
<?php
?>
<?php if (!empty($_SESSION["products"]) || count($cart_custom) > 0) { ?>
<form method="POST" action="winkelwagen.php" style="width:60%; float:left; position:relative; left: 50%;">
<table class="margin_top" style="float: left; position: relative; left: -50%;">
<tr>
<th data-field="id" colspan="1" style="width: 15%;"></th>
<th data-field="id" colspan="1" style="width: 35%;">Naam</th>
<th data-field="id" colspan="1" style="width: 35%;">Aantal</th>
<th data-field="id" colspan="1" style="width: 15%;">Prijs</th>
</tr>
<?php if(count($cart_custom) > 0){ ?>
<?php
$total_price = 0;
foreach($cart_custom as $key=>$val){
$cookie_model = $cart_custom[$key]['model'];
$cookie_price = $cart_custom[$key]['price'];
$model_name = $cookie_model['model'];
if($model_name == "wranglan_model"){
$model_img = "image/t-shirt.png";
}elseif($model_name == "round_model"){
$model_img = "image/t-shirt.png";
}
$model_qty = str_replace(",",".",$cookie_price['qty']);
$model_price = $model_qty * $cookie_price['ttl_price'];
$total_price = $model_qty * $cookie_price['ttl_price'] + $total_price;
if(isset($_GET['remove_id'])){
unset($cart_custom[$_GET['remove_id']]);
setcookie('view_cart_custom_fab', json_encode($cart_custom), time() + (86400 * 2), "/");
header("location: winkelwagen.php");
}
?>
<tr>
<td colspan='1' style="width: 15%;">
<img src='<?php echo $model_img; ?>' alt='' class='img_table responsive_img' />
</td>
<td colspan='1' style="width: 35%;">
T-shirt op smaak
</td>
<td colspan='1' style="width: 35%;">
<input id='update_cart' name='update_cart' type='hidden' value='' />
<input class="qty" type="text" name="custom_qty_cart[<?php echo $key; ?>]" value="<?php echo $model_qty; ?>" style="width: 20%; text-align:right;"/>
<input name='Update' style="width: 18px; vertical-align:bottom" type='image' value='update_cart' src='/image/update.jpg' alt='Update' onclick = "return setHidden('update_cart');" />
<img src="/image/recycle.jpg" style="width: 18px; vertical-align:bottom">
</td>
<td colspan='1' style="width: 15%;">
<?php echo price_format($model_price); ?>
</td>
</tr>
<?php
}
?>
<?php } ?>
<?php if(!empty($_SESSION["products"])){?>
<?php
if (isset($_SESSION["products"]) && count($_SESSION["products"]) > 0) {
$total = 0;
$list_tax = '';
foreach ($_SESSION["products"] as $product) { //Print each item, quantity and price.
//print_r($_SESSION["products"]);
$product_name = $product["fabric_name"];
$product_id = $product["id"];
//$product_qty = ($product["fabric_qty"] > 1 ? $product["fabric_qty"]:1);
$product_qty = str_replace(",",".",$product["fabric_qty"]);
//$product_price = ($product_qty>1 ? $product["fabric_price"] * $product_qty : $product["fabric_price"]);
$product_price = ($product["fabric_price"] * $product_qty);
$product_code = $product["product_code"];
$product_color = $product["product_color"];
$product_size = $product["product_size"];
$item_price = $product_price;
$total_cost_price = $total_cost_price + $item_price;
//$item_price = sprintf("%01.2f",($product_price * $product_qty)); // price x qty = total item price
if(isset($_GET['removeid'])){
unset($_SESSION["products"][$_GET['removeid']]);
header("location: winkelwagen.php");
}
$cart_box .=
"<tr><td colspan='1' style='width: 15%'><img src='admin/images/fabric/" . $product['fabric_texture'] . "' alt='' class='img_table responsive_img' /></td>
<td colspan='1' style='width: 35%'>$product_name</td>
<td colspan='1' style='width: 35%'>
<input id='update_cart' name='update_cart' type='hidden' value='' />
<input type='text' name='qty[]' class='qty' min='1' max='100' value='".$product_qty."' style='width: 20%; text-align:right;'/>
<input name='Update' style='width: 18px; vertical-align:bottom' type='image' value='update_cart' src='/image/update.jpg' alt='Update' onclick = 'return setHidden('update_cart');' />
<a href='?removeid=$product_id' style='width: 18px; vertical-align:bottom'><img src='/image/recycle.jpg' style='width: 18px; vertical-align:bottom'></a>
<input type='hidden' name='product_id[]' value='".$product_id."' /></td>
<td colspan='1' style='width: 15%'>".price_format($item_price)."</td>";
$subtotal = ($product_price * $product_qty); //Multiply item quantity * price
$total = ($total + $subtotal); //Add up to total price
}
$grand_total = $total + $shipping_cost; //grand total
foreach ($taxes as $key => $value) { //list and calculate all taxes in array
$tax_amount = round($total * ($value / 100));
$tax_item[$key] = $tax_amount;
$grand_total = $grand_total + $tax_amount;
}
foreach ($tax_item as $key => $value) { //taxes List
$list_tax .= $key . ' ' . $currency . sprintf("%01.2f", $value) . '<br />';
}
$shipping_cost = ($shipping_cost) ? 'Shipping Cost : ' . $currency . sprintf("%01.2f", $shipping_cost) . '<br />' : '';
echo $cart_box;
}
?>
<?php } ?>
<?php
$fetch_shipping_price = mysqli_query($conn,"SELECT * FROM `st_custom_price` WHERE `meta_key`='shipping'");
$fetch_price = mysqli_fetch_array($fetch_shipping_price);
$shipping_price = $fetch_price['meta_price'];
$product_total = $total_price + $total_cost_price + ($price_detail['ttl_price']*$price_detail['qty']);
if($_SESSION['price_coupon_price']){
$total_amount = $total_price + $total_cost_price + ($price_detail['ttl_price']*$price_detail['qty']) - $_SESSION['price_coupon_price'];
$_SESSION['price_coupon_value'] = $_SESSION['price_coupon_price'];
}elseif($_SESSION['price_coupon_percent']){
$total_amount = $total_price + $total_cost_price + ($price_detail['ttl_price']*$price_detail['qty']);
$percent_total = ($_SESSION['price_coupon_percent'] / 100) * $total_amount;
$_SESSION['price_coupon_value'] = $percent_total;
$total_amount = $total_amount - $percent_total;
}else{
$total_amount = $total_price + $total_cost_price + ($price_detail['ttl_price']*$price_detail['qty']);
}
$ttl_ship = $total_amount + $shipping_price;
setcookie('total_cost', $ttl_ship, time() + (86400 * 2), "/");
setcookie('total_cost', $ttl_ship, time() + (86400 * 2), "/");
?>
<?php if(!empty($total_amount) || count($cart_custom) > 0){ ?>
<tr>
<th data-field="id" colspan="3" style="width: 85%;">Totaal</th>
<th data-field="id" colspan="1" style="width: 15%;"> <?php echo price_format($product_total); ?></th>
</tr>
<?php if($_SESSION['price_coupon_price'] || $_SESSION['price_coupon_percent']){
$discount_type = ($_SESSION['coupon_data']['coupon_type'] == "price" ? " €" : " percent ");
?>
<tr>
<th data-field="id" colspan="3" style="width: 85%;">
<input id='remove_coupon_btn' name='remove_coupon_btn' type='hidden' value='' />
Kortingscode <?php echo $_SESSION['coupon_data']['coupon_name']; ?><input name='remove_coupon_btn' style="width: 18px; vertical-align:bottom" type='image' value='remove_coupon_btn' src='/image/recycle.jpg' alt='Remove coupon' onclick = "return setHidden('remove_coupon_btn');" />
</th>
<th style="width: 15%;"><?php echo price_format($total_amount-$product_total); ?></th>
</tr>
<?php } ?>
<tr>
<th data-field="id" colspan="3" style="width: 85%;">Verzendingskosten</th>
<th data-field="id" colspan="1" style="width: 15%;"> <?php echo price_format($shipping_price); ?></th>
</tr>
<tr>
<th data-field="id" colspan="3" style="width: 85%;">Te betalen</th>
<th data-field="id" colspan="1" style="width: 15%;"> <?php echo price_format($ttl_ship); ?></th>
</tr>
</table>
<?php echo $message; ?>
<div class="more-products-pagination" style="float: left; position: relative; left: -50%;">
<div class="coupon_row" style="margin:5px 20px">
<?php if($_SESSION['price_coupon_price'] || $_SESSION['price_coupon_percent']){ ?>
<?php } else { ?>
<ul>
<li>Kortingscode</li>
<li><input type="text" name="coupon_apply" value=""><input type="submit" name="apply_coupon_btn" value="Toepassen" class="add_to_cart_btn" style="border: 1px solid #fff; display: inline-block;float: right;"></li>
</ul>
<?php } ?>
</div>
<div class="pagination_btn pagination_btn_right">
<input type="submit" class="add_to_cart_btn" value="Afrekenen" name="checkout_btn">
</div>
</div>
<?php } ?>
</form>
<?php }else {
echo "Geen producten in uw winkelwagen.";
}?>
</div>
</div>
<script language="javascript">
function setHidden(whichButton)
{
var element = document.getElementById(whichButton);
element.value = whichButton;
return true;
}
</script>
<?php
include_once("inc/footer.php");
?>
<style>
table {
border-collapse: collapse;
width: 100%;
background: rgba(253, 245, 208,0.6);
box-shadow: 0px 0px 2px #C1C1C1;
}
th, td {
text-align: left;
padding: 8px;
color:#444;
}
td{
}
th {
background-color: #BD3F6F;
color: white;
font-weight: 400;
font-size: 16px;
}
</style>
When I then try to access the variable $_SESSION['coupon_data'] on a different page this does not work, it is empty.
I set the variable here in this code:
if(isset($_POST['apply_coupon_btn'])){
$query_coupon = mysqli_query($conn,"SELECT * FROM `st_coupon` WHERE `coupon_code`='{$_POST['coupon_apply']}' AND `status`='1'");
$fetch_coupon = mysqli_fetch_array($query_coupon);
$message = "tmp2";
if(isset($fetch_coupon)){
$_SESSION['coupon_data'] = $fetch_coupon;
..
}
And then I call the next page here:
if(isset($_POST['checkout_btn'])){
if($_SESSION['USER_EMAIL']){
header("location: afrekenen.php");
}else{
header("location: winkelwagen.php#login-modelbox");
}
}
Even if I call the update of the cart items in this same page, the session variables disapear for some reason which I do not understand:
if(isset($_POST['update_cart']))
{
echo "update cart";
foreach($_POST['custom_qty_cart'] as $key=>$qtys){
$cart_custom[$key]['price']['qty'] = $qtys;
}
setcookie('view_cart_custom_fab', json_encode($cart_custom), time() + (86400 * 2), "/");
setcookie('custom_qty', $_POST['custom_qty'], time() + (86400 * 2), "/");
$custom_total = $custom_total*$_POST['custom_qty'];
setcookie('custom', $custom_total, time() + (86400 * 2), "/");
foreach($_POST["qty"] as $key => $qty) { //Print each item, quantity and price.
$id = $_POST["product_id"][$key];
$_SESSION["products"][$id]["fabric_qty"] = $qty;
}
header("location: winkelwagen.php");
}
I am utterly baffled and hope someone can help me out.
issue resolved, turns out there was another call to session_start in one of the includes which was creating a separate session and hence not allowing the correct globalisation.
i have a wordpress website and with customization (cache/minify/database), is really quick in frontend, and in backend, with one exception. I use a plugin where it stores and retrieves players stats, carreers, teams etc.
When saving the team's match player's statistics, it needs 5 minutes to show the page reloaded with the data.
Also when retrieving for example team's season data, it also needs a lot of time to show them.
From what i ve seen, it is related with two of my files that do all the work. tournament_match.php, and functions.php. From hosting they said that it gets all tha database and thats why it is so slow
Here is the tournament_match file
<?php
global $wpdb;
global $msg;
$page = $_GET['page'];
$tournament_id = $_GET['tid'];
$match_id = $_GET['mid'];
$league_type = leagueengine_fetch_data_from_id($tournament_id,'league_type');
if(isset($_POST['home_team_bonus']) or isset($_POST['away_team_bonus'])) {
if(isset($_POST['save_tournament_match'])) { leagueengine_save_tournament_match($tournament_id,$match_id,$_POST['date_alt'],$_POST['time_alt'],$_POST['home_team_id'],$_POST['away_team_id'],$_POST['home_team_score'],$_POST['away_team_score'],$_POST['home_team_bonus'],$_POST['away_team_bonus']); }
} else {
if(isset($_POST['save_tournament_match'])) { leagueengine_save_tournament_match($tournament_id,$match_id,$_POST['date_alt'],$_POST['time_alt'],$_POST['home_team_id'],$_POST['away_team_id'],$_POST['home_team_score'],$_POST['away_team_score']); }
}
if(isset($_POST['save_attributes'])) { leagueengine_save_attribute_values('tournament_match',NULL,NULL,$match_id,NULL,NULL,$tournament_id); }
if(isset($_POST['add_event_to_match'])) { error_reporting(0); leagueengine_add_event_to_tournament_match($tournament_id,$match_id,$_POST['new_event_id'],$_POST['new_event_time'],$_POST['timeline_text'],$_POST['new_event_count'],$_POST['new_event_player_id']); error_reporting(1); }
if(isset($_POST['save_events'])) { leagueengine_save_event_times('tournament_match',$_POST['event_time_id'],$_POST['event_time'],$_POST['event_text']); }
if(isset($_POST['add_home_event_to_match'])){
error_reporting(0);
foreach($_POST as $key=>$val){
$val=intval($val);
if(is_int($val)&&$val>0){
$data=explode('-',$key);
$playerid=$data[1];
$eventid=$data[2];
leagueengine_add_event_to_tournament_match2($tournament_id,$match_id,$eventid,$_POST['new_event_time'],$_POST['timeline_text'],$val,$playerid);
}
}
error_reporting(1);
}
if(isset($_POST['add_away_event_to_match'])){
error_reporting(0);
foreach($_POST as $key=>$val){
$val=intval($val);
if(is_int($val)&&$val>0){
$data=explode('-',$key);
$playerid=$data[1];
$eventid=$data[2];
leagueengine_add_event_to_tournament_match2($tournament_id,$match_id,$eventid,$_POST['new_event_time'],$_POST['timeline_text'],$val,$playerid);
}
}
error_reporting(1);
}
if(isset($_POST['save_tournament_match_lineups'])) {
if(isset($_POST['homeplayers'])) { $homeplayers = $_POST['homeplayers']; } else { $homeplayers = ''; }
if(isset($_POST['awayplayers'])) { $awayplayers = $_POST['awayplayers']; } else { $awayplayers = ''; }
if(isset($_POST['homesubs'])) { $homesubs = $_POST['homesubs']; } else { $homesubs = ''; }
if(isset($_POST['awaysubs'])) { $awaysubs = $_POST['awaysubs']; } else { $awaysubs = ''; }
leagueengine_save_tournament_match_lineups($tournament_id,$match_id,$homeplayers,$awayplayers,$homesubs,$awaysubs);
}
if(isset($_POST['delete_events'])) { leagueengine_delete_data('tournament_match_event',$_POST['delete_id'],'tournament',NULL,NULL,$tournament_id,$match_id); }
if(isset($_POST['save_match_statistics'])) { leagueengine_save_tournament_match_statistics($tournament_id,$match_id,$_POST['tournament_match_statistic'],$_POST['home_value'],$_POST['away_value'],$_POST['att_type']); }
if(isset($_POST['save_tournament_match_preview'])) { leagueengine_save_tournament_match_preview($tournament_id,$match_id,stripslashes_deep($_POST['match_preview'])); }
if(isset($_POST['save_tournament_match_report'])) { leagueengine_save_tournament_match_report($tournament_id,$match_id,stripslashes_deep($_POST['match_report'])); }
if(isset($_POST['tournament_match_swap'])) { leagueengine_tournament_match_swap($tournament_id,$match_id); }
$table = $wpdb->prefix . 'leagueengine_tournament_matches';
$match = $wpdb->get_row("SELECT * FROM $table WHERE tournament_id = '$tournament_id' AND id = '$match_id'");
$home_team_id = $match->home_team_id;
$away_team_id = $match->away_team_id;
$tournament = leagueengine_fetch_data_row('tournament',$tournament_id);
$table2 = $wpdb->prefix . 'leagueengine_tournaments';
$tournament_row = $wpdb->get_row("SELECT * FROM $table2 WHERE data_id = '$tournament_id'");
?>
<div id="leagueengine_admin" class="<?php echo $page; ?>">
<?php echo leagueengine_admin_header(); ?>
<div id="leagueengine_admin_content">
<?php if($msg) { echo $msg; } ?>
<ul class="breadcrumbs">
<li><?php _e('Competitions','leagueengine');?> <span class="divider">/</span></li>
<li><?php echo leagueengine_fetch_data_from_id($tournament_id,'data_value') ?> <span class="divider">/</span></li>
<?php if($match->round == 'GROUP') { ?>
<li><?php _e('Groups','leagueengine');?> <span class="divider">/</span></li>
<?php } else { ?>
<li><?php _e('Knockout','leagueengine');?> <span class="divider">/</span></li>
<?php } ?>
<li><?php _e('Match','leagueengine');?></li>
</ul>
<?php
if($league_type == 'players') {
$home_emblem = leagueengine_fetch_player_emblem($match->home_team_id,20);
$away_emblem = leagueengine_fetch_player_emblem($match->away_team_id,20,'right');
} else {
$home_emblem = leagueengine_fetch_team_emblem($match->home_team_id,20);
$away_emblem = leagueengine_fetch_team_emblem($match->away_team_id,20,'right');
}
?>
<div class="match_masthead">
<table>
<tr>
<td class="home_team" style="border-top: 5px solid <?php echo leagueengine_fetch_team_colour($match->home_team_id,'primary');?>; text-align:left;width:40%;"><?php echo $home_emblem . leagueengine_fetch_data_from_id($match->home_team_id,'data_value');?></td>
<td class="score" style="text-align:center;width:20%;"><span><?php echo $match->home_team_score;?> ‐ <?php echo $match->away_team_score;?></span></td>
<td class="away_team" style="border-top: 5px solid <?php echo leagueengine_fetch_team_colour($match->away_team_id,'primary');?>; text-align:right;width:40%;"><?php echo leagueengine_fetch_data_from_id($match->away_team_id,'data_value') . $away_emblem;?></td>
</tr>
<tr>
<td colspan="3" style="text-align:center;"><?php echo date(leagueengine_fetch_settings('date_format_php'),strtotime($match->match_date)) . ' ' . date(leagueengine_fetch_settings('time_format_php'),strtotime($match->match_time)); ?></td>
</tr>
<tr>
<td class="competition" colspan="3" style="text-align:center;"><?php echo '' . leagueengine_fetch_data_from_id($tournament_id,'data_value') . ''; ?></td>
</tr>
<tr><td colspan="100%" style="text-align:center;padding-bottom:20px;"><?php echo leagueengine_link('tournament_match&tid='.$tournament_id.'&mid='.$match->id,__('Go To Match','leagueengine'),'','','button-primary'); ?></td></tr>
</table>
</div>
<div id="leagueengine_tabs">
<ul>
<li><?php _e('Score','leagueengine');?></li>
<?php
$table = $wpdb->prefix . 'leagueengine_player_careers';
$homeplayers = $wpdb->get_results("SELECT * FROM $table WHERE tournament_id = '$tournament_id' AND team_id = '$home_team_id'");
$awayplayers = $wpdb->get_results("SELECT * FROM $table WHERE tournament_id = '$tournament_id' AND team_id = '$away_team_id'");
if($homeplayers or $awayplayers && $league_type != 'players') {
?>
<li><?php _e('Lineups','leagueengine');?></li>
<?php } ?>
<?php if(leagueengine_data_exists('event')) { echo '<li>' . __('Events','leagueengine') . '</li>'; } ?>
<?php if(leagueengine_statistics_exists('tournament_match')) { echo '<li>' . __('Statistics','leagueengine') . '</li>'; } ?>
<?php if(leagueengine_h2h_history($match->match_date,$home_team_id,$away_team_id)) { echo '<li>' . __('History','leagueengine') . '</li>'; } ?>
<li><?php _e('Report','leagueengine');?></li>
</ul>
<div id="score">
<form action="" method="POST">
<table class="form">
<tr>
<th style="width:20%;"><?php _e('Date/Time','leagueengine');?></th>
<th style="width:30%;text-align:center;"><?php _e('Home','leagueengine');?></th>
<th style="width:20%;text-align:center;"><?php _e('Score','leagueengine');?></th>
<th style="width:30%;text-align:center;"><?php _e('Away','leagueengine');?></th>
</tr>
<tr class="date">
<td><input type="text" class="leagueengine_datepicker" name="match_date" value="<?php echo date(leagueengine_fetch_settings('date_format_php'),strtotime($match->match_date));?>"></td>
<td colspan="3"></td>
</tr>
<input type="hidden" name="tournament_match_id" value="<?php echo $match->id;?>">
<input type="hidden" name="home_team_id" value="<?php echo $match->home_team_id;?>">
<input type="hidden" name="away_team_id" value="<?php echo $match->away_team_id;?>">
<input type="hidden" name="date_alt" class="leagueengine_datepicker_alt" value="<?php echo $match->match_date;?>">
<input type="hidden" name="time_alt" class="leagueengine_timepicker_alt" value="<?php echo $match->match_time;?>">
<tr>
<td><input type="text" class="leagueengine_timepicker" name="match_time" value="<?php echo date(leagueengine_fetch_settings('time_format_php'),strtotime($match->match_time));?>"></td>
<td style="text-align:center;"><?php echo leagueengine_fetch_data_from_id($match->home_team_id,'data_value') ;?></td>
<td style="text-align:center;">
<input style="width:48%;text-align:center;" type="text" name="home_team_score" value="<?php echo $match->home_team_score;?>">
<input style="width:48%;text-align:center;" type="text" name="away_team_score" value="<?php echo $match->away_team_score;?>">
</td>
<td style="text-align:center;"><?php echo leagueengine_fetch_data_from_id($match->away_team_id,'data_value') ;?></td>
</tr>
<?php if($tournament_row->pts_bonus == 'on') { ?>
<tr>
<td></td>
<td style="text-align:center;"><?php _e('Bonus Points','leagueengine');?></td>
<td style="text-align:center;">
<input style="width:48%;text-align:center;" type="text" name="home_team_bonus" value="<?php echo $match->home_team_bonus;?>">
<input style="width:48%;text-align:center;" type="text" name="away_team_bonus" value="<?php echo $match->away_team_bonus;?>">
</td>
<td style="text-align:center;"><?php _e('Bonus Points','leagueengine');?></td>
</tr>
<?php } ?>
</table>
<input style="margin-top:20px;" type="submit" name="save_tournament_match" class="button-primary" value="<?php _e('Save','leagueengine');?>" />
<input style="margin:20px 0 0 10px;" type="submit" name="tournament_match_swap" class="button" value="<?php _e('Swap Teams','leagueengine');?>" style="float:right;margin-right:10px;" />
</form>
</div>
<?php
$table = $wpdb->prefix . 'leagueengine_player_careers';
$homeplayers = $wpdb->get_results("SELECT * FROM $table WHERE tournament_id = '$tournament_id' AND team_id = '$home_team_id'");
$awayplayers = $wpdb->get_results("SELECT * FROM $table WHERE tournament_id = '$tournament_id' AND team_id = '$away_team_id'");
if($homeplayers or $awayplayers && $league_type != 'players') {
?>
<div id="lineups">
<?php echo leagueengine_tournament_match_lineups($tournament_id,$match_id);?>
</div>
<?php } ?>
<?php if(leagueengine_data_exists('event')) { ?>
<div id="events">
<?php echo leagueengine_tournament_match_events($tournament_id,$match_id);?>
</div>
<?php } ?>
<?php if(leagueengine_statistics_exists('tournament_match')) { ?>
<div id="statistics">
<?php echo leagueengine_fetch_statistics('tournament_match',NULL,NULL,$tournament_id,$match_id);?>
</div>
<?php } ?>
<?php if(leagueengine_h2h_history($match->match_date,$home_team_id,$away_team_id)) { ?>
<div id="history">
<?php echo leagueengine_fetch_h2h_history($match->match_date,$home_team_id,$away_team_id);?>
</div>
<?php } ?>
<div id="report">
<form action="" method="post">
<div class="setting">
<table class="form">
<tr><th><?php _e('Match Report','leagueengine');?></th></tr>
</table>
<?php wp_editor( stripslashes_deep($match->report), 'match_report', array( 'media_buttons' => true, 'tinymce' => true, 'quicktags' => true, 'textarea_rows' => 20 )); ?>
</div>
<input style="margin-top:20px;" type="submit" name="save_tournament_match_report" class="button-primary" value="<?php _e('Save','leagueengine'); ?>">
</form>
</div>
</div>
</div>
</div>
</div>
I am new to php, i want to create my own e-commerce website. i stuck at the very final stage , to create cash on delivery database.
i want to insert all selected product title or id with quantity in one column
my database table
order_id
order_product ----here i want all selected product_id or title with quantity
Please help
<?php require_once("config.php"); ?>
<?php
if(isset($_GET['add'])) {
$query = query("SELECT * FROM products WHERE product_id=".escape_string($_GET['add'])." ");
confirm($query);
while($row = fetch_array($query)) {
if($row['product_quantity'] != $_SESSION['product_' . $_GET['add']]) {
$_SESSION['product_' . $_GET['add']] +=1;
redirect("../public/checkout.php");
}else{
set_message("We only have" . $row['product_quantity'] . " " . " available");
redirect("../public/checkout.php");
}
}
}
if(isset($_GET['remove'])) {
$_SESSION['product_' . $_GET['remove']]--;
if($_SESSION['product_' . $_GET['remove']] < 1) {
unset($_SESSION['item_total']);
redirect("../public/checkout.php");
}else{
redirect("../public/checkout.php");
}
}
if(isset($_GET['delete'])) {
$_SESSION['product_' . $_GET['delete']] = '0';
unset($_SESSION['item_total']);
redirect("../public/checkout.php");
}
function cart() {
$total = 0;
$item_quantity = 0;
$item_name = 1;
$item_number = 1;
$amount = 1;
$quantity = 1;
foreach ($_SESSION as $name => $value) {
if($value > 0 ) {
if(substr($name, 0, 8) == "product_"){
$length = strlen($name - 8);
$id = substr($name, 8 , $length);
$query = query("SELECT * FROM products WHERE product_id = " . escape_string($id)." ");
confirm($query);
while($row = fetch_array($query)) {
$sub = $row['product_price']*$value;
$item_quantity +=$value;
$product = <<<DELIMETER
<tr>
<td data-th="Product">
<div class="row">
<div class="col-sm-2 hidden-xs"><img src="http://placehold.it/100x100" alt="..." class="img-responsive"/></div>
<div class="col-sm-10">
<h4 class="nomargin">{$row['product_title']}</h4>
</div>
</div>
</td>
<td data-th="Price">₹{$row['product_price']}</td>
<td data-th="Quantity">
<button class="btn btn-info btn-sm"><i class="fa fa-minus"></i></button>
{$value} <button class="btn btn-info btn-sm"><i class="fa fa-plus"></i></button>
</td>
<td data-th="Subtotal" class="text-center">₹{$sub}</td>
<td class="actions" data-th="">
<button class="btn btn-info btn-sm"><i class="fa fa-trash-o"></i></button>
</td>
</tr>
<input type="hidden" name="item_name_{$item_name}" value="{$row['product_title']}">
<input type="hidden" name="item_number_{$item_number}" value="{$row['product_id']}">
<input type="hidden" name="amount_{$amount}" value="{$row['product_price']}">
<input type="hidden" name="quantity_{$quantity}" value="{$value}">
DELIMETER;
echo $product;
$item_name++;
$item_number++;
$amount++;
$quantity++;
}
$_SESSION['item_total'] = $total += $sub;
$_SESSION['item_quantity'] = $item_quantity;
}
}
}
}
function show_checkout(){
if(isset($_SESSION['item_quantity'])){
$query = query(" SELECT * FROM products");
confirm($query);
while ($row = fetch_array($query)) {
$checkout_button = <<<DELIMETER
<td><a name="checkout" href="thank_you.php?pi={$row['product_title']}" type="submit" class="btn btn-success btn-block">Checkout<i class="fa fa-angle-right"></i></a></td>
DELIMETER;
return $checkout_button;
}
}
}
?>
I am attempting to update the code for my web page's search function, right now it is not returning anything. I have been working with it for a little while and not getting anything out of it.
This is the HTML search code:
<form method="post" action="words_results1.php">
<table align="center">
<tr>
<td>Keyword</td>
<td><input type="text" name="Keyword" /></td>
</tr>
<tr>
<td>Author</td>
<td><input type="text" name="Author" /></td>
</tr>
<tr>
<td valign=bottom>Words Posted<BR />on or before</td>
<td valign=top>
<table>
<tr>
<td width="33%">Day</td>
<td width="33%">Month</td>
<td width="34%">Year</td>
</tr>
<tr>
<td>
<select name=Day>
<?php
echo '<option></option>';
for($count = 1; $count <= 31; ++$count)
{
echo "<option>$count</option>";
}
?>
</select>
</td>
<td>
<select name=Month>
<?php
echo '<option></option>';
for($count = 1; $count <= 12; $count++)
{
echo "<option value=$count>".date("M", mktime(0,0,0,$count,1, 2000))."</option>";
}
?>
</select>
</td>
<td>
<select name=Year>
<?php
echo '<option></option>';
for($count = date("Y"); $count >= 1997; $count--)
{
echo "<option>$count</option>";
}
?>
</select>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan=2 align=center>
<BR />
<input type="submit" value="Search" />
<input type="submit" name="cancel" value="Cancel" />
</td>
</tr>
</table>
</form>
PHP
<?php
if(isset($_POST['cancel']))
{
echo("index.html");
exit;
}
$qry_string = "SELECT * FROM Words";
$search = "";
if(!empty($Keyword))
{
$End_String = "(Word LIKE '%$Keyword%' OR Title LIKE '%$Keyword%')";
$search .="&Keyword=$Keyword";
}
if(!empty($Author))
{
if(isset($End_String))
{
$End_String .= " AND (Author LIKE '%$Author%')";
}
else
{
$End_String = "(Author LIKE '%$Author%')";
}
$search .="&Author=$Author";
}
if(!empty($Day))
{
if(isset($End_String))
{
$End_String .= " AND (DAYOFMONTH(Date_Created) = '$Day')";
}
else
{
$End_String = "(DAYOFMONTH(Date_Created) = '$Day')";
}
$search .="&Day=$Day";
}
if(!empty($Month))
{
if(isset($End_String))
{
$End_String .= "AND (MONTH(Date_Created) = '$Month')";
}
else
{
$End_String = "(MONTH(Date_Created) = '$Month')";
}
$search .="&Month=$Month";
}
if(!empty($Year))
{
if(isset($End_String))
{
$End_String .= " AND (YEAR(Date_Created) = '$Year')";
}
else
{
$End_String = "(YEAR(Date_Created) = '$Year')";
}
$search .="&Year=$Year";
}
if (!isset($offset)) $offset=0;
if(isset($End_String))
{
$qry_string = $qry_string." WHERE ".$End_String . " ORDER BY Date_Created DESC LIMIT $offset,101";
}
else
{
$qry_string = $qry_string." ORDER BY Date_Created DESC LIMIT $offset,101";
}
// echo $qry_string . "<P><HR><P>";
$result = mysql_query($qry_string);
echo mysql_error();
?>
This last bit is the code that forms the table, I have an assumption that the problem lies here but honestly am not sure at this point
<table style="margin: 5px 15px; 5px 20px;" align="center" bgcolor="#666666" border="0" cellpadding="3" cellspacing="1">
<tbody><tr style="background: #04C1DE; font-family: Verdana; font-weight: bold; font-size: 18px;">
<td style="width: 50%; padding: 5px;">
Word
</td>
<td style="width: 20%; padding: 5px;">
Author
</td>
<td style="width: 10%; padding: 5px;">
Date
</td>
<td>Category</td>
<td>Active?</td>
<td> </td>
<td> </td>
</tr>
</tbody>
</tr>
<?php
$count = 1;
$bgc = 0;
while($row = mysql_fetch_array($sql))
{
if ($count > 100) break;
echo '<tr style="background: ';
if ($bgc==0) echo "#FFFFFF";
else echo "#CFEBFD";
$bgc == 0?$bgc=1:$bgc=0;
echo ';">';
echo "<td><a href=../../words/display_word.php?ID=$row[ID]>$row[Title]</a></td>";
echo "<td>$row[Author]</td><td>$row[Display_Date]</td><td>$row[category]</td>";
if($row[active])
{
echo "<td>YES</td>";
}
else
{
echo "<td>NO</td>";
}
echo "<td>$row[link_count]</td>";
if($row[Title] != "")
{
echo "<td><a href=words_edit.html?ID=$row[ID]>Edit</a></td></tr>";
}
else
{
echo "</tr>";
}
$count++;
}
?>
It seems,you are not collecting the value of
$Keyword=$_POST['Keyword'];
and add ,closing table tag to display the results in the table format correctly.
I am creating a component for teachers where in teacher can generate pdf for all the students who have completed the course.
Checking all the students and pdfs should be generated and saved on disk. After which a download link is provided to download the zip of all the pdfs generated. This is what i want to achieve. I am using fpdf for generating pdf.
Any suggestions ?
Below is the form that is posted and students id-
<form
action="<?php echo JRoute::_('index.php?option=com_mentor&view=download_certificate&cid=' . $cid . '&Itemid=529') ?>"
name="download_certificate" method="post" id="download_certificate">
<table class="adminlist" border="1" cellpadding="0" cellspacing="0"
style="table-layout: fixed" id="content">
<thead>
<tr>
<th class="nowrap" style="width: 35px">
<input type="checkbox" name="selectall" id="selectall">
</th>
<th class="nowrap" align="center">
<?php echo JText::_('COM_MENTOR_USER_NAME'); ?>
</th>
<th class="nowrap" style="width: 140px">
<?php echo JText::_('COM_MENTOR_COURSE_STATUS'); ?>
</th>
<th class="nowrap" style="width: 140px">
<?php echo JText::_('COM_MENTOR_ENROLLMENT_DATE'); ?>
</th>
<th class="nowrap" style="width: 140px">
<?php echo JText::_('COM_MENTOR_ACTIVITY'); ?>
</th>
<th class="nowrap" style="width: 50px">
<?php echo JText::_('COM_MENTOR_SCORE'); ?>
</th>
<th class="nowrap" style="width: 50px">
<?php echo JText::_('COM_MENTOR_RESULT'); ?>
</th>
</tr>
</thead>
<tbody>
<?php
//echo '<pre>';print_r($this->mentor_details); die;
foreach ($this->mentor_details as $students) {
$cid = $this->mentor_details['cid'];
$i = 1;
foreach ($students['students'] as $student) {
$userid = $student['id'];
// echo '<pre>';
// print_r($student);
// die;
?>
<tr class="status" id="<?php echo $userid ?>">
<td align="center">
<input type="checkbox" id="<?php echo $userid ?>" name="check[]" class="checkbox1"
value="<?php echo $userid ?>">
</td>
<td>
<a href="<?php echo JRoute::_('index.php?option=com_mentor&view=grader&cid=' . $cid . '&uid='
. $userid . $itemid) ?>">
<?php echo $student['username']; ?>
</a>
</td>
<!-- <td>
<?php// echo $student['email']; ?>
</td> -->
<td align="center">
<?php
$incomplete = $completed = $not_started = 0;
for ($k = 0; $k < count($student['elements']); $k++) {
foreach ($student['elements'] as $elements) {
if ($elements['userid'] == $userid) {
// echo '<pre>';print_r($elements); die;
if ($elements['element']['cmi.core.lesson_status'] == 'incomplete') {
$incomplete++;
} else {
$completed++;
}
}
}
}
if ($incomplete == 0 && $completed == 0) {
echo 'Not yet started';
} else {
if ($completed == count($student['elements'])) {
echo 'Completed';
} else {
echo 'Incomplete';
}
}
?>
</td>
<td align="center">
<?php
if (!empty($student['timestart'])) {
$date = date('d-m-Y H:i', $student['timestart']);
echo $date;
} else {
echo "Not yet started";
} ?>
</td>
<td align="center">
<?php
if (!empty($student['activity']['lasttime']) && (!empty($student['activity']['starttime']))) {
$start_date = date('d-m-Y H:i', $student['activity']['starttime']);
$last_date = date('d-m-Y H:i', $student['activity']['lasttime']);
echo $start_date . '<br/>' . $last_date;
} else {
echo "-";
} ?>
</td>
<td align="center">
<?php
$grades = $student['grades'];
$total_grade = array();
$j = 0;
//for ($j = 0; $j < count($grades); $j++) {
// $total_grade[$j] = $grades[$j]['finalgrade'];
//}
//print_r($total_grade);die;
if (!empty($grades)) {
//echo number_format(array_sum($total_grade), 2);
$total_grade[$j] = $grades[$j]['finalgrade'];
echo number_format($total_grade[$j], 2);
} else {
echo '-';
}
//echo '<pre>';
//print_r($student['grades']);
//die;
?>
</td>
<td align="center">
<?php
//echo '<pre>';print_r($student);die;
if (!empty($student['scores'])) {
if (isset($grades[$j]['feedbacktext'])) {
echo $grades[$j]['feedbacktext'];
} else {
echo '-';
}
} else {
echo '-';
}
?>
</td>
</tr>
<?php $i++;
}
} ?>
</tbody>
</table>
</form>
<script>
function checked_value() {
var checkedValue = [];
var $len = $(".checkbox1:checked").length;
if ($len == 0) {
alert('Please select user');
}
// else if ($len > 1) {
// alert('Please select a single user only.');
// }
else {
$(".checkbox1").each(function () {
var $this = $(this);
if ($this.is(":checked")) {
checkedValue.push($this.attr("id"));
}
});
$("#download_certificate").submit();
</script>
On Clicking image tag, form is submitted with the students id and I am getting students data, his name, grades, course,
<img src="/components/com_mentor/images/certificate_blue.png" class="certificate-ico right"
title="Download Certificate" onclick="checked_value();"/>
After this processing, page is redirected to pdf.php page
require_once('/wamp/opt/bitnami/apache2/htdocs/lms/lib/fpdf/fpdf.php');
$pdf = new FPDF(); $pdf->SetFont('times', '', 12);
$pdf->SetTextColor(50, 60, 100); $pdf->AddPage('L');
$pdf->SetDisplayMode(real, 'default'); $pdf->SetXY(10, 60);
$pdf->SetFontSize(12);
$pdf->Write(5, 'Dear Ms.XYX');
$filename = "test.pdf";
$dir = "/assets/";
$pdf->Output($dir . $filename, 'F');
Thanks guys for your help.. Solved my question.
Looped through the pdf function for n no. of users.