I am trying to edit a PHP IF statement however, there is a syntax issue according to this online validator:
http://www.piliapp.com/php-syntax-check/
Here is the code:
<?php
if (strpos($row['caption'],'DIGITAL') !== false)
{?><input type="button" class="item_add" id="s<?php echo $n; ?>" value="Add to cart"/>
<?php } ?>
<?php
elseif (strpos($row['price'] != NULL && strpos($row['price']) != '0' && strpos($row['caption'],'DIGITAL') !== true)
{?><input type="button" class="item_add" id="s<?php echo $n; ?>" value="Add to cart"/>
<?php } ?>
This is what I a trying to achieve:
If the "Caption" begins with the text "DIGITAL" then the add to cart button should be active.
If the "Caption does not begin with the text "DIGITAL" AND the "Price" is not NULL or 0 then the shopping cart button should be active. In all other instances, it should be INACTIVE.
Here is the full source code:
<?php include_once('admin/config/config.php'); ?>
<?php include_once('admin/libs/functions.php'); ?>
<?php $obj = new Functions(); ?>
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
<link rel="stylesheet" type="text/css" href="reset.css">
<link rel="stylesheet" type="text/css" href="text.css">
<link rel="stylesheet" type="text/css" href="960.css">
<link rel="stylesheet" type="text/css" href="styles.css">
<link rel="stylesheet" type="text/css" href="assets/css/style.css">
<link rel="stylesheet" type="text/css" href="assets/css/nivo-lightbox.css">
<link rel="stylesheet" type="text/css" href="assets/css/default.css">
<script type="text/javascript" src="assets/js/jquery-2.1.1.js"></script>
<script type="text/javascript" src="assets/js/nivo-lightbox.js"></script>
<script type="text/javascript">
$(function(){
$(".view-img").nivoLightbox();
});
</script>
<script type="text/javascript" src="assets/js/shoppingcart.js"></script>
<script type="text/javascript" src="assets/js/general.js"></script>
<meta charset="utf-8">
<meta name="description" content="CENSORED Photography provides the best quality photography in the SENSORED Region. Whether you are looking for a photographer for a wedding, portrait, event or literally anything else, Let your story begin with SENSORED Photography. ">
<meta name="keywords" content="Photography, , Videography, , Photo, Portrait, Best">
<title>SENSORED Photography</title>
<script type="text/javascript">
$(function(){
$(".item_size").change(function(){
item_val = $(this).val();
n = $(this).attr("custval");
if(item_val != "" && item_val != null) {
$("#s"+n).removeAttr("disabled");
}
else {
$("#s"+n).attr("disabled","disabled");
}
});
});
</script>
</head>
<!-- oncontextmenu="return false;"-->
<body>
<div id="wrapper" class="container_12">
<div id="sidebar" class="grid_3">
<img src="images/sidebar_02.png" alt="sidebar"/>
<ul>
<li class="home">HOME</li>
<li class="about">ABOUT</li>
<li class="contact">CONTACT</li>
<li class="gallery" style="color:#AD6FC4;">GALLERY</li>
</ul>
<p>© Copyright SENSORED 2013</p>
</div><!--end sidebar-->
<div id="content" class="grid_9">
<div id="contact" class="grid_3 alpha push_6">
</div><!--end contact-->
<div id="shop_cart">
<span class="shop_cart_quantity"></span> items
<span class="totalfront"></span><span class="shop_cart_total"></span>
View Details
Checkout
Empty Cart
</div>
<div id="cart_overview" style="background: #ffffff; position: absolute; top: 10px; left: 10px; display: none">
<div id="cart_overviewitems" class="shop_cart_items"></div>
<div style="clear:left"></div>
</div>
<div id="action_overview" style="position: absolute; top: 10px; left: 10px; display: none">
<!-- Product Added -->
<div style="clear:left"></div>
</div>
<div id="content2" class="omega grid_9 content2 newpages">
<?php if(isset($_GET['cat']) && $_GET['cat']!= NULL): ?>
<?php
$query = "SELECT * FROM categories WHERE id={$_GET['cat']}";
$data = $obj->select($query);
?>
<h1 class="normalh1 newpagesnew"><?php echo strtoupper($data['name']); ?></h1>
<?php
if($data['protected'] == '1'):
?>
<?php
$cid = $_GET['cat'];
$cookName = "cat".$cid;
if(!isset($_COOKIE[$cookName]) || $_COOKIE[$cookName] != "checked"):
?>
<div id="formWrap">
<form action="category-login.php" method="post" id="category_login">
<?php if(isset($_GET['mess']) && $_GET['mess'] == "err"): ?>
<p>Incorrect Password. Please try again.</p>
<?php else: ?>
<p>This gallery is protected. Please enter the password.</p>
<?php endif; ?>
<input type="hidden" name="cid" value="<?echo $cid; ?>" />
<div class="row">
<div class="input">
<input type="password" id="password" class="detail" name="password" placeholder="Password" required />
</div><!-- end .input -->
</div><!-- end .row -->
<div class="submit">
<input type="submit" id="submit" name="submit" value="login"/>
</div><!-- end .submit -->
</form>
</div>
<?php else: ?>
<?php
$sql = "SELECT * FROM categories WHERE parent_id = {$_GET['cat']} ORDER BY id DESC";
$res = $obj->selectAll($sql);
if($res):
?>
<?php $flag = 1; ?>
<?php foreach($res as $dat): ?>
<div class="grid_2 gal product">
<a href="viewgallery.php?cat=<?php echo $dat['id']; ?>">
<?php
$sql1 = "SELECT * FROM images WHERE category_id={$dat['id']} AND cover=1";
$dat1 = $obj->select($sql1);
if($dat1):
?>
<img src="gal/thumbs/<?php echo $dat1['filename']; ?>" />
<?php else:?>
<img src="images/nopic.png" />
<?php endif; ?>
</a>
<span>
<a href="viewgallery.php?cat=<?php echo $dat['id']; ?>"><?php echo $dat['name']; ?>
</a>
</span>
</div>
<?php endforeach; ?>
<?php endif; ?>
<?php if($flag == 1): ?>
<hr />
<?php endif; ?>
<?php
$n=1;
$query1 = "SELECT * FROM images WHERE category_id={$data['id']} ORDER BY id DESC";
$result = $obj->selectAll($query1);
if($result):
?>
<?php foreach($result as $row): ?>
<div class="grid_2 gal product">
<div class="product_item">
<a class="view-img" href="gal/<?php echo $row['filename']; ?>" data-lightbox-gallery="gallery1" <?php echo $row['caption'] != NULL ? 'title="'.$row['caption'].'"' : ''; ?>>
<img src="gal/thumbs/<?php echo $row['filename']; ?>">
</a>
<span class="item_name" style="display:none">Photo <?php echo $data['id']."-".$row['id']; ?></span>
<?php if($row['price'] != NULL && $row['price'] != '0'): ?><span style="margin-bottom: 0">Price: <i class="item_price"><?php echo $row['priceunit'].$row['price']; ?></i></span> <?php endif; ?>
<input type="hidden" class="item_quantity" value="1" style="width:20px;">
<?php if($row['price'] != NULL && $row['price'] != '0'): ?>
<?php
$sql = "SELECT * FROM sizes";
$res = $obj->selectAll($sql);
?>
<select name="item_size" class="item_size" custval="<?php echo $n; ?>" required>
<option value="">Select Size</option>
<?php foreach($res as $line): ?>
<option value="<?php echo $line['width'].' x '.$line['height']; ?>"><?php echo $line['width'].' x '.$line['height']; ?></option>
<?php endforeach; ?>
</select>
<input type="button" class="item_add" id="s<?php echo $n; ?>" value="Add to cart" disabled />
<?php else: ?>
<div style="height:100px; float: left; clear:both"></div>
<?php endif; ?>
</div>
</div>
<?php $n++; ?>
<?php endforeach; ?>
<?php else: ?>
<?php if($flag != 1): ?>
No Image avilable.
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
<?php else: ?>
<?php
$sql = "SELECT * FROM categories WHERE parent_id = {$_GET['cat']} ORDER BY id DESC";
$res = $obj->selectAll($sql);
if($res):
?>
<?php $flag = 1; ?>
<?php foreach($res as $dat): ?>
<div class="grid_2 gal product">
<a href="viewgallery.php?cat=<?php echo $dat['id']; ?>">
<?php
$sql1 = "SELECT * FROM images WHERE category_id={$dat['id']} AND cover=1";
$dat1 = $obj->select($sql1);
if($dat1):
?>
<img src="gal/thumbs/<?php echo $dat1['filename']; ?>" />
<?php else:?>
<img src="images/nopic.png" />
<?php endif; ?>
</a>
<span>
<a href="viewgallery.php?cat=<?php echo $dat['id']; ?>"><?php echo $dat['name']; ?>
</a>
</span>
</div>
<?php endforeach; ?>
<?php endif; ?>
<?php if($flag == 1): ?>
<hr />
<?php endif; ?>
<?php
$n=1;
$query1 = "SELECT * FROM images WHERE category_id={$data['id']} ORDER BY id DESC";
$result = $obj->selectAll($query1);
if($result):
?>
<?php foreach($result as $row): ?>
<div class="grid_2 gal product">
<div class="product_item">
<a class="view-img" href="gal/<?php echo $row['filename']; ?>" data-lightbox-gallery="gallery1" <?php echo $row['caption'] != NULL ? 'title="'.$row['caption'].'"' : ''; ?>>
<img src="gal/thumbs/<?php echo $row['filename']; ?>">
</a>
<span class="item_name" style="display:none">Photo <?php echo $data['id']."-".$row['id']; ?></span>
<?php if($row['price'] != NULL && $row['price'] != '0'): ?><span style="margin-bottom: 0">Price: <i class="item_price"><?php echo $row['priceunit'].$row['price']; ?></i></span> <?php endif; ?>
<input type="hidden" class="item_quantity" value="1" style="width:20px;">
<?php if($row['price'] != NULL && $row['price'] != '0'): ?>
<?php
$sql = "SELECT * FROM sizes";
$res = $obj->selectAll($sql);
?>
<select name="item_size" class="item_size" custval="<?php echo $n; ?>" required <?php if (strpos($row['caption'],'DIGITAL') !== false) {?>disabled="disabled"<?php }?>>
<option value="">Select Size</option>
<?php foreach($res as $line): ?>
<option value="<?php echo $line['width'].' x '.$line['height']; ?>"><?php echo $line['width'].' x '.$line['height']; ?></option>
<?php endforeach; ?>
</select>
<?php
if (strpos($row['caption'],'DIGITAL') !== false)
{?><input type="button" class="item_add" id="s<?php echo $n; ?>" value="Add to cart"/>
<?php } ?>
<?php
elseif (strpos($row['price'] != NULL && strpos($row['price']) != '0' && strpos($row['caption'],'DIGITAL') !== true)
{?><input type="button" class="item_add" id="s<?php echo $n; ?>" value="Add to cart"/>
<?php } ?>
<?php else: ?>
<div style="height:100px; float: left; clear:both"></div>
<?php endif; ?>
</div>
</div>
<?php $n++; ?>
<?php endforeach; ?>
<?php else: ?>
<?php if($flag != 1): ?>
No Image avilable.
<?php endif; ?>
<?php endif; ?>
<?php endif;?>
<?php else: ?><!-- post -->
<h1 class="normalh1">Invalid action.</h1>
<?php endif;?>
</div><!--end content2-->
</div><!--end content-->
</div><!--end wrapper-->
<script type="text/javascript" src="assets/js/docevents.js"></script>
</body>
</html>
<!-- Localized -->
Can someone advise why I cannot get my code to validate? it looks fine to me.
The validator states " Parse error: syntax error, unexpected "{" in CODE on line 271.
Error Parsing CODE"
The code returns 500 Internal server error if I run it.
The error is in your elseif condition
(strpos($row['price'] != NULL && strpos($row['price']) != '0' && strpos($row['caption'],'DIGITAL') !== true)
^^ ^
|missing ")" missing 2nd argument
missing 2nd argument
I can't even tell what you're trying to do here. Also, strpos will never return boolean true so your check at the end of this line will never be successful.
I would also suggest using PHP's alternative syntax for control structure when mixing PHP and HTML. Something like this...
<?php if (strpos($row['caption'],'DIGITAL') !== false) : ?>
<input type="button" class="item_add" id="s<?= $n ?>" value="Add to cart"/>
<?php elseif (/* some other logic */) : ?>
<input type="button" class="item_add" id="s<?= $n ?>" value="Add to cart"/>
<!-- this line is exactly the same as the previous one?!? -->
<?php endif ?>
You can check below code in http://www.piliapp.com/php-syntax-check/ url for validation and get "No syntax errors detected in CODE" message.
You can use this code instead of your code definitely work.
<?php if (strpos($row['caption'],'DIGITAL') !== false){ ?>
<input type="button" class="item_add" id="s<?php echo $n; ?>" value="Add to cart"/>
<?php } elseif ($row['price'] != NULL && $row['price'] != '0' && strpos($row['caption'],'DIGITAL') !== true) {?>
<input type="button" class="item_add" id="s<?php echo $n; ?>" value="Add to cart"/>
<?php } ?>
This got the code to work:
<?php if (strpos($row['caption'],'DIGITAL') !== false){ ?>
<input type="button" class="item_add" id="s<?php echo $n; ?>" value="Add to cart"/>
<?php }
elseif ($row['price'] != NULL && $row['price'] != '0' && strpos($row['caption'],'DIGITAL') !== true) {?>
<input type="button" class="item_add" id="s<?php echo $n; ?>" value="Add to cart"/>
<?php } ?>
<?php else: ?>
<div style="height:100px; float: left; clear:both"></div>
<?php endif; ?>
Related
I have a block being displayed on my homepage which shows a product, whose id we specify. The code on homepage (static block) looks like this:
{{block type="core/template" product_id="2559" template="catalog/product/one_product.phtml"}}
The one_product.phtml file contains this code:
<?php
$productId = $this->getProduct_id();
$product = Mage::getModel('catalog/product')->load($productId); //load product
?>
<div class="product">
<a href="<?php echo $product->getProductUrl() ?>" >
<img class="product-img" src="<?php echo $this->helper('catalog/image')->init($product, 'image'); ?>"alt="<?php echo $this->htmlEscape($product->getName()) ?>" />
</a>
</div>
<div class="product-detail">
<P><?php // echo $this->htmlEscape($product->getName()) ?>
<?php $prod_name = $this->htmlEscape($product->getName()); ?>
<?php
$count_str = strlen($prod_name);
if ($count_str < 40) {
echo $prod_name;
} else {
$offset = 0;
$length = 41;
$prod_name = html_entity_decode($prod_name);
echo htmlentities(mb_substr($prod_name,0,$length,'utf-8')). "...";;
}
?>
</P>
<!--?php $price = $product->getPrice() ; ?-->
<?php $_product = Mage::getModel('catalog/product')->load($product->getId());
$productBlock = $this->getLayout()->createBlock('catalog/product_price');
?>
<span>
<?php echo $productBlock->getPriceHtml($_product); ?>
<?php $tier_price = end($_product->getTierPrice());
if($tier_price !='0'){ ?>
<span>As Low As:</span>
<?php
echo " ₹ ".number_format( $tier_price['price']);
} ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart"
onclick="setLocation('<?php echo Mage::helper('checkout/cart')->getAddUrl($product); ?>')">
</span>
</div>
So basically I want to show random products out of the ones I specify separated by commas. For eg: I specify in the static block product_id="2559,2661,2857,9293" and it should show any one of those 4 products randomly.
What is the way to do that?
Also any way to make it pull products from SKU also? Since we remember all the SKUs but we have to check each product ID everytime we change the product here.
Please excuse me if the question is too basic, I'm not a developer.
You can see it in action at www.giftzila.com
Thanks!
Create a new file called random-product.phtml at app/design/frontend/default/Your_Theme/template/catalog/random-product.phtml then add the following code in that file
<?php
$chosen_category = Mage::getModel('catalog/category')->load($this->getCategoryId());
$_productCollection = $this->getLoadedProductCollection();
$number_of_products = $this->getNumProducts();
if (sizeof($_productCollection) < $number_of_products) {
$number_of_products = sizeof($_productCollection);
}
$displayed_products = array();
foreach ($_productCollection as $_product) {
$displayed_products[] = $_product;
}
$random_products = array();
if (sizeof($_productCollection) > 1) {
$random_products = array_rand($displayed_products, $number_of_products);
} else {
$random_products = array('0');
}
?>
<?php if(!$_productCollection->getSize()):?>
<div class="note-msg">
<?=$this->__('There are no products matching the selection.')?>
</div>
<?php else:?>
<div class="main-binder">
<div class="cms-box">
<div class="category-title">
<h2>Random Products</h2>
</div>
<div class="category-products">
<table id="products-grid-table" class="products-grid">
<?php
$k=0;
for ($i=0; $i < $number_of_products; $i++): ?>
<?php if ($k == 0) { ?>
<tr class="first odd">
<?php } if($k==3) { $k=0; ?>
</tr><tr class="first odd even">
<?php } ?>
<td id="td_<?php echo ($k+1); ?>" <?php if($k==3){ ?>class="last"<? } ?> >
<div class="cms-box">
<div id="cont_<?php echo ($k+1); ?>">
<div class="product-name-block">
<?php
$pname=$this->htmlEscape($displayed_products[$random_products[$i]]->getName());
?>
<h3 class="product-name">
<a href="<?php echo $displayed_products[$random_products[$i]]->getProductUrl()?>" title="<?php echo $pname; ?>">
<?php if(strlen($pname) > 28) {echo substr($pname,0,25)."...";}else {echo $pname;}?>
</a></h3>
</div>
<div class="image-box">
<a class="product-image" href="<?php echo $displayed_products[$random_products[$i]]->getProductUrl()?>"> <img src="<?php echo $this->helper('catalog/image')->init($displayed_products[$random_products[$i]], 'small_image')->resize(140);?>" alt="<?php echo $this->htmlEscape($displayed_products[$random_products[$i]]->getName())?>" title="<?php echo $this->htmlEscape($displayed_products[$random_products[$i]]->getName())?>"/> </a>
</div>
<div class="cms-price-box" style=" text-align:center;">
<span class="regular-price" id="product-price-37">
<span class="price" ><?php echo Mage::app()->getLocale()->currency(Mage::app()->getStore()->
getCurrentCurrencyCode())->getSymbol().$displayed_products[$random_products[$i]]->getPrice(); ?></span>
</span>
</div>
<div class="button-row" style="text-align:center;">
<button onclick="setLocation('<?php echo $displayed_products[$random_products[$i]]->getProductUrl();?>')" class="button" type="button"><span><span><span>Details</span></span></span></button>
<button onclick="setLocation('<?php echo $this->getUrl('')."/checkout/cart/add?product=".$displayed_products[$random_products[$i]]->getId()."&qty=1" ?>')" class="button"><span><?php echo $this->__('Add to Cart') ?></span></button>
</div>
</div>
</div></td>
<?php $k++; ?>
<?php endfor;?>
</tr>
</table>
</div>
</div>
</div>
<?php endif;?>
Now call block in your cms home page by adding following code:-
{{block type="catalog/product_list" category_id="3" num_products="8" template="catalog/random-product.phtml"}}
it's my first post...
I have a problem with a php file that was modifie, but not from me.
In a menu item i found this error:
1054 Unknown column 'Array' in 'where clause' SQL=SELECT * FROM #__content WHERE Array = '4'
And in another menu item I found this:
Warning: Invalid argument supplied for foreach() in .../home/templates/rt_nuance/html/com_tags/tag/default.php on line 113
This is my .php file:
<?php
/**
* #package Joomla.Site
* #subpackage com_tags
*
* #copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
* #license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
// Note that there are certain parts of this layout used only when there is exactly one tag.
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers');
$isSingleTag = (count($this->item) == 1);
?>
<div class="tag-category<?php echo $this->pageclass_sfx; ?>">
<?php if ($this->params->get('show_page_heading')) : ?>
<h1>
<?php echo $this->escape($this->params->get('page_heading')); ?>
</h1>
<?php endif; ?>
<?php if ($this->params->get('show_tag_title', 1)) : ?>
<h2>
<?php echo JHtml::_('content.prepare', $this->tags_title, '', 'com_tag.tag'); ?>
</h2>
<?php endif; ?>
<?php // We only show a tag description if there is a single tag. ?>
<?php if (count($this->item) == 1 && (($this->params->get('tag_list_show_tag_image', 1)) || $this->params->get('tag_list_show_tag_description', 1))) : ?>
<div class="category-desc">
<?php $images = json_decode($this->item[0]->images); ?>
<?php if ($this->params->get('tag_list_show_tag_image', 1) == 1 && !empty($images->image_fulltext)) : ?>
<img src="<?php echo htmlspecialchars($images->image_fulltext); ?>">
<?php endif; ?>
<?php if ($this->params->get('tag_list_show_tag_description') == 1 && $this->item[0]->description) : ?>
<?php echo JHtml::_('content.prepare', $this->item[0]->description, '', 'com_tags.tag'); ?>
<?php endif; ?>
<div class="clr"></div>
</div>
<?php endif; ?>
<?php // If there are multiple tags and a description or image has been supplied use that. ?>
<?php if ($this->params->get('tag_list_show_tag_description', 1) || $this->params->get('show_description_image', 1)): ?>
<?php if ($this->params->get('show_description_image', 1) == 1 && $this->params->get('tag_list_image')) : ?>
<img src="<?php echo $this->params->get('tag_list_image'); ?>">
<?php endif; ?>
<?php if ($this->params->get('tag_list_description', '') > '') : ?>
<?php echo JHtml::_('content.prepare', $this->params->get('tag_list_description'), '', 'com_tags.tag'); ?>
<?php endif; ?>
<?php endif; ?>
<?php echo $this->loadTemplate('items'); ?>
<?php if (($this->params->def('show_pagination', 1) == 1 || ($this->params->get('show_pagination') == 2)) && ($this->pagination->get('pages.total') > 1)) : ?>
<div class="pagination">
<?php if ($this->params->def('show_pagination_results', 1)) : ?>
<p class="counter pull-right"> <?php echo $this->pagination->getPagesCounter(); ?> </p>
<?php endif; ?>
<?php echo $this->pagination->getPagesLinks(); ?>
</div>
<?php endif; ?>
<?php
jimport('joomla.application.component.controller');
$app = JFactory::getApplication();
//j3 compatibility
if(!defined('DS')){
define('DS',DIRECTORY_SEPARATOR);
}
JLoader::register('J2StoreController', JPATH_COMPONENT.'/controllers/controller.php');
JLoader::register('J2StoreModel', JPATH_ADMINISTRATOR.'/components/com_j2store/models/model.php');
JLoader::register('J2StoreView', JPATH_ADMINISTRATOR.'/components/com_j2store/views/view.php');
require_once (JPATH_ADMINISTRATOR.'/components/com_j2store/library/base.php');
require_once (JPATH_SITE.'/components/com_j2store/helpers/utilities.php');
require_once (JPATH_ADMINISTRATOR.'/components/com_j2store/library/prices.php');
require_once (JPATH_ADMINISTRATOR.'/components/com_j2store/helpers/strapper.php');
require_once (JPATH_ADMINISTRATOR.'/components/com_j2store/version.php');
require_once (JPATH_SITE.'/components/com_j2store/models/products.php');
J2StoreStrapper::addJS();
J2StoreStrapper::addCSS();
$tes_prod = new J2StoreModelProducts();
$tes_prod->setId('118');
$test_item = $tes_prod->getItem();
$test_data = J2StoreHelperCart::getItemInfo('118');;
?>
<h1 style="color#f00">TAG</h1>
<link href="<?php echo JURI::base().'media/j2store/css/j2store-product.css' ?>" rel="stylesheet" type="text/css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.imagesloaded/3.1.8/imagesloaded.pkgd.js"></script>
<style>
.sm-row-fluid :nth-child(3n+4){margin-left:0; clear: both; }
.sm-row-fluid + table{display:none;}
.j2store-item-title-link {display:block;}
</style>
<div class="row-fluid sm-row-fluid">
<?php foreach( $this->items as $value):
$this_prod_obj = new J2StoreModelProducts();
$this_prod_obj->setId($value->content_item_id);
$item = $this_prod_obj->getItem();
$product = array(
'id' => $value->content_item_id,
'name' => $item->product_name,
'main_image' => $item->main_image ,
'price' => number_format ( $item->item_price, 2 ),
'special_price' => number_format ( $item->special_price, 2 ),
'discount' => number_format ( 100-($item->special_price*100/$item->item_price), 0 ),
'url' => JURI::base().'outfit/view/'.$value->content_item_id.'-'.$item->product_name
);
?>
<div class="span4 sm-product-box" >
<div class="j2store-product-single j2store-product-single-113 column-1" itemscope="" itemtype="http://schema.org/Product">
<!-- on Before display product -->
<div class="j2store-before-display-product">
</div>
<!-- Form action starts here -->
<form action="/carrello" method="post" name="j2storeProductForm" id="j2store-product-list" class="j2storeProductForm">
<!-- Before displaying product Images -->
<div class="j2store-before-display-productimages">
</div>
<a itemprop="url" class="j2store-item-title-link" href="<?php echo $product['url'] ?>">
<img class="j2store-item-productlist-thumbimage" itemprop="image" src="<?php echo $product['main_image'] ?>" alt="<?php echo $product['name'] ;?>">
</a>
<!-- Title -->
<h3 class="j2store-item-title" itemprop="name">
<a itemprop="url" class="j2store-item-title-link" href="<?php echo $product['url'] ?>">
<?php echo $product['name']; ?>
</a>
</h3>
<div class="sm-product-hoover" style="position: absolute; top:0; left: 0; bottom: 0; right: 0; width: 100%; height:100%; display: none;">
<!-- Title -->
<h1 class="j2store-item-title" itemprop="name">
<a itemprop="url" class="j2store-item-title-link" href="<?php echo $product['url'] ?>">
<?php echo $product['name']; ?>
</a>
</h1>
<div class="j2store-product-prices">
<span class="j2store-product-item-label">Prezzo</span>
<?php if($product['special_price'] > 0) echo '<strike>';?>
<span itemprop="offers" itemscope="" itemtype="http://schema.org/Offer">
<span itemprop="price" class="text" id="product_price_113"><?php echo $product['price'].' €'; ?></span>
</span>
<?php if($product['special_price'] > 0): echo '</strike>';?>
<span class="product-discount-offer" itemprop="offers" itemscope="" itemtype="http://schema.org/Offer">
<?php echo 'Sconto:'. $product['discount'].' %'; ?>
</span>
<span itemprop="offers" itemscope="" itemtype="http://schema.org/Offer">
<span itemprop="price" id="product_special_price_113" class="product-special-price"><?php echo $product['special_price'].' €'; ?></span>
</span>
<?php endif; ?>
</div>
<a id="addtoCartBtn" href="<?php echo $product['url'] ?>" type="submit" class="j2store-item-cart-button button " value="Aggiungi al carrello">Aggiungi al carrello</a>
</div>
</form>
</div><!-- end item -->
</div>
<?php endforeach; ?>
</div>
</div>
Thanks to everyone...
You are returning an array where it needs to be a string in your query
Specifically, where there there should be a column name you are getting a PHP array. As a result, PHP converts that array to string that says "Array" before sending it off to MySQL.
I have a problem with my code in php.
Error: Undefined Variable 'id'.
<?php
include_once '../includes/connection.php';
include_once '../includes/functions.php';
session_start();
$posts = $pdo->query("SELECT * FROM posty ORDER BY post_id DESC");
$j=0;
?>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="../sources/css/style.css">
<script type="text/javascript" src="../sources/scripts/time.js"></script>
<script type="text/javascript" src="../sources/scripts/scroll.js"></script>
</head>
<body onload="timeLine(); setInterval('timeLine()', 1000 )" >
<header>
<div class = "menu">
<ul>
<li> Blog </li>
<li> Archives </li>
<li> Contact </li>
<li id="addPost"> Add Post </li>
<li id="editPost"> Edit Post </li>
<li id="deletePost"> Delete Post </li>
<li id="showBlogContent"> Hide Blog </li>
<li id="menuRightLogin"> Logout </li>
<li id="menuRightDate"><?php echo date('jS F Y').' '; ?><span id="clock"> </span> </li>
</ul>
</div>
</header>
<div id="showBlog" style="display: block;">
<div class="container">
<div class="postsContainer">
<?php foreach($posts as $post) {
if ($j <= 5) { ?>
<div class="postBox">
<div class="postTitle">
<br />
<?php echo $post['post_title']; ?>
</div>
<div class="postContent">
<br />
<?php if(($wordCount = str_word_count($post['post_content']) <=50)) {
echo $post['post_content'];?>
Edit Post
<br />
<?php } else {
echo excerpts($post['post_content'], 50).'... <br/> <br/>
Edit Post
<br /> <br />';
} ?>
</div>
<div class="postDate">
<?php echo '<b id="author">Author:</b> '.$post['post_author'].' <b id="posted">posted:</b> '.date('jS F Y', $post['add_date']); ?>
</div>
</div>
<?php $j++; } }?>
</div>
</div>
<footer>
<small> © Copyright 2015, n3stis </small>
</footer>
</div>
</body>
</html>
So from here I'm sending a 'id' to edit form:
<?php
include_once '../includes/connection.php';
include_once '../includes/functions.php';
session_start();
$id = $_GET['id'];
if (isset ($id)) {
if (isset($_SESSION['logged_in'])) {
$query = $pdo->prepare("SELECT * FROM posty WHERE post_id='" . $id . "' LIMIT 1");
$query->execute();
$post = $query->fetch();
if (isset($_POST['post_title'], $_POST['post_content'], $_POST['post_author'])) {
$postTitle = $_POST['post_title'];
$postAuthor = $_POST['post_author'];
$postContent = nl2br($_POST['post_content']);
$postTime = time();
if (empty($post_title) or empty($post_content) or empty($post_author)) {
$error = 'All fields required.';
} else {
$sql = ("UPDATE `posty` SET `post_title` = :title, `post_author` = :author, `post_content` = :content, `edit_date` = :editDate WHERE `post_id` = :postID ");
$query = $pdo->prepare($sql);
$query->bindValue(':title', $postTitle);
$query->bindValue(':author', $postAuthor);
$query->bindValue(':content', $postContent);
$query->bindValue(':editDate', $postTime);
$query->bindValue(':postID', $id);
$query->execute();
header('Location: adminPanel.php');
}
}
?>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="../sources/css/style.css">
<script type="text/javascript" src="../sources/scripts/time.js"></script>
<script type="text/javascript" src="../sources/scripts/scroll.js"></script>
</head>
<body onload="timeLine(); setInterval('timeLine()', 1000 )">
<header>
<div class="menu">
<ul>
<li> Blog </li>
<li> Archives </li>
<li> Contact </li>
<li id="#addPost"> Add Post </li>
<li id="#editPost"> Edit Post </li>
<li id="#deletePost"> Delete Post </li>
<li id="showBlogContent"> Hide Blog </li>
<li id="menuRightLogin"> Logout </li>
<li id="menuRightDate"><?php echo date('jS F Y') . ' '; ?><span id="clock"> </span></li>
</ul>
</div>
</header>
<div id="showBlog" style="display: block;">
<div class="container">
<div class="postsContainer">
<?php if (isset($error)) { ?>
<p id="error"><?php echo $error ?> </p>
<?php } ?>
<form action="editPostPanel.php" method="post">
<input type="text" name="post_title" value="<?php echo $post['post_title'];?>"/>
<input type="text" name="post_author" value="<?php echo $post['post_author'];?>"/>
<br/>
<br/>
<textarea name="post_content" rows="15" cols="90"><?php echo $post['post_content'];?></textarea>
<br/>
<br/>
<input type="submit" value="Wyślij post"/>
</form>
</div>
</div>
<footer>
<small> © Copyright 2015, n3stis </small>
</footer>
</div>
</body>
</html>
<?php
} else {
echo 'Error';
} }
else {
echo 'Error';
}
When I send a form I get this:
Notice: Undefined index: id on line 7
I will be very greatfull for yours help :)
change
$id = $_GET['id'];
if (isset ($id))
to
if (isset ($_GET['id'])) {
$id = $_GET['id'];
Your form doesn't have the id parameter in it. You need to change
<form action="editPostPanel.php" method="post">
to:
<form action="editPostPanel.php?id=<?php echo $id; ?>" method="post">
This is in addition to correcting the isset check that the other answers noted:
if (isset($_GET['id'])) {
$id = $_GET['id'];
While I don't have your line numbers, I'd guess that line 7 is $id = $_GET['id'];. This indicates that you don't have a GET (query) param called id set. To fix that Notice, you probably want to swap the two lines as follows:
if (isset($_GET['id'])){
$id = $_GET['id']
But all that will do is start echoing 'Error' back to you. You'll also want to figure out why your line editPostPanel.php?id='.$post['post_id'] is not apparently setting the id as desired.
I am stuck and I am desperate. Here is the problem:
I have a div "container" that includes all the other divs.
But somehow the div ends where the first php statement is! Magic I say.
I want the container div to hold the whole page, but it reaches the first php statement (that includes the code from another file into the page) and ends. I can't find the reason.
Code.
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>{subTITLE}<?php echo TITLE; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<meta http-equiv="description" content="{subDESCRIPTION}<?php echo DESCRIPTION; ?>">
<meta http-equiv="keywords" content="<?php echo KEYWORDS; ?>">
<link type="text/css" rel="stylesheet" href="<?php echo ABSWEBTPLPATH; ?>main.css">
</head>
<body>
<div class="superbar">
<div class="menuSearch">
<span>
<?php ShowSearchForm(); ?>
</span>
</div>
</div>
<div class="container">
<?php include(TPLPATH.'header.php'); ?>
<br/><br/><br/>
<div class="content">
<div class="contentLeft">
<div class="cLhead">
<h4>
Categories
</h4>
</div>
<ul class="categories">
<?php ShowMenu(); ?>
</ul>
</div>
<span class="contentRight">
<?php ListGoods(); ?>
</span>
</div>
<?php include(TPLPATH.'footer.php'); ?>
</div>
</body>
</html>
PHP of header.php
<div class="header-container">
<div class="wrapper">
</div>
<div id="header_top_right">
<div class="btn1">
<span class="menuPokupki"><div class="description">Мои покупки</div><div class="descriptionSub"><nobr>история покупок</nobr></div></span>
</div>
<div class="btn2">
<span>
<h5 >Мой магазин</h5>
</span>
</div>
<form action="<?php echo ABSWEBPATH; ?>ch_rt.php" method="post">
<span class="cnt">
Валюта:
<select name="rt" class="sorting">
<?php
session_start();
if(isset($_SESSION["rt"]) && !empty($_SESSION["rt"])) {
if($_SESSION["rt"] == "wmr" or $_SESSION["rt"] != "wmz" or $_SESSION["rt"] != "wme" or $_SESSION["rt"] != "wmu") {
echo "<option value=\"wmr\" selected=\"selected\">руб. (RUR)</option>\r\n"; }
else {echo "<option value=\"wmr\">руб. (RUR)</option>\r\n";}
if($_SESSION["rt"] == "wmz") {
echo "<option value=\"wmz\" selected=\"selected\">$ (USD)</option>\r\n"; }
else {echo "<option value=\"wmz\">$ (USD)</option>\r\n";}
if($_SESSION["rt"] == "wme") {
echo "<option value=\"wme\" selected=\"selected\">€ (EUR)</option>\r\n"; }
else {echo "<option value=\"wme\">€ (EUR)</option>\r\n";}
if($_SESSION["rt"] == "wmu") {
echo "<option value=\"wmu\" selected=\"selected\">грн. (UAH)</option>\r\n"; }
else {echo "<option value=\"wmu\">грн. (UAH)</option>\r\n";} }
else {
if(isset($default_rt) && !empty($default_rt)) {
if($default_rt == "wmr" or $default_rt != "wmz" or $default_rt != "wme" or $default_rt != "wmu") {
echo "<option value=\"wmr\" selected=\"selected\">руб. (RUR)</option>\r\n"; }
else {echo "<option value=\"wmr\">руб. (RUR)</option>\r\n";}
if($default_rt == "wmz") {
echo "<option value=\"wmz\" selected=\"selected\">$ (USD)</option>\r\n"; }
else {echo "<option value=\"wmz\">$ (USD)</option>\r\n";}
if($default_rt == "wme") {
echo "<option value=\"wme\" selected=\"selected\">€ (EUR)</option>\r\n"; }
else {echo "<option value=\"wme\">€ (EUR)</option>\r\n";}
if($default_rt == "wmu") {
echo "<option value=\"wmu\" selected=\"selected\">грн. (UAH)</option>\r\n"; }
else {echo "<option value=\"wmu\">грн. (UAH)</option>\r\n";} }
else {
echo "<option value=\"wmr\" selected=\"selected\">руб. (RUR)</option>
<option value=\"wmz\">$ (USD)</option>
<option value=\"wme\">€ (EUR)</option>
<option value=\"wmu\">грн. (UAH)</option>\r\n"; } }
?>
</select>
<input type="submit" value="Установить" class="button" />
</form></span></div>
</div>
<div class="subheader">
<ul class="menu">
<li class="menu1" noWrap>О магазине</li>
<li class="menu1" noWrap>Способы оплаты</li>
<li class="menu1" noWrap>Контакты</li>
<span class="filter">
<span class="sortingTitle">Сортировка:</span>
<span class="sortingSelect">
<?php GoodsSort(); ?>
</span>
</span>
</ul>
</div>
</div>
</div>
CSS has 500 lines so I uploaded it to pastebin
sorry for terrible crap code. I have to urgently edit someone else's and I already hate him
http://pastebin.com/6b5UC9mj
Too many closing divs in header.php
Take the last one out
Your span is closed outside the form. Your current structure is :
<form action="<?php echo ABSWEBPATH; ?>ch_rt.php" method="post">
<span class="cnt">
....
</form>
</span>
Must be:
<form action="<?php echo ABSWEBPATH; ?>ch_rt.php" method="post">
<span class="cnt">
....
</span>
</form>
this code out put is here....(look at the footer subscribe section )
<?php if(!empty($this->items))foreach($this->items as $level): ?>
<?php
$formatedPrice = sprintf('%1.02f',$level->price);
$dotpos = strpos($formatedPrice, '.');
$price_integer = substr($formatedPrice,0,$dotpos);
$price_fractional = substr($formatedPrice,$dotpos+1);
?>
<div class="level akeebasubs-level-<?php echo $level->akeebasubs_level_id ?>">
<p class="level-title">
<span class="level-price">
<?php if(AkeebasubsHelperCparams::getParam('currencypos','before') == 'before'): ?>
<span class="level-price-currency"><?php echo AkeebasubsHelperCparams::getParam('currencysymbol','€')?></span>
<?php endif; ?>
<span class="level-price-integer"><?php echo $price_integer ?></span><?php if((int)$price_fractional > 0): ?><span class="level-price-separator">.</span><span class="level-price-decimal"><?php echo $price_fractional ?></span><?php endif; ?>
<?php if(AkeebasubsHelperCparams::getParam('currencypos','before') == 'after'): ?>
<span class="level-price-currency"><?php echo AkeebasubsHelperCparams::getParam('currencysymbol','€')?></span>
<?php endif; ?>
</span>
<span class="level-title-text">
<a href="<?php echo JRoute::_('index.php?option=com_akeebasubs&view=level&slug='.$level->slug.'&format=html&layout=default')?>">
<?php echo $this->escape($level->title)?>
</a>
</span>
</p>
<div class="level-inner">
<div class="level-description">
<div class="level-description-inner">
<?php if(!empty($level->image)):?>
<img class="level-image" src="<?php echo JURI::base()?><?php echo trim(AkeebasubsHelperCparams::getParam('imagedir','images/'),'/') ?>/<?php echo $level->image?>" />
<?php endif;?>
<?php echo JHTML::_('content.prepare', AkeebasubsHelperMessage::processLanguage($level->description));?>
</div>
</div>
<div class="level-clear"></div>
<div >
<button onclick="window.location='<?php echo JRoute::_('index.php?option=com_akeebasubs&view=level&slug='.$level->slug.'&format=html&layout=default')?>'">
<?php echo JText::_('COM_AKEEBASUBS_LEVELS_SUBSCRIBE')?>
</button>
</div>
</div>
</div>
<?php endforeach; ?>
this is the language file contain that name
COM_AKEEBASUBS_LEVELS_SUBSCRIBE="Subscribe Now"
I want to name those three sections butons as 6month,12month,24month
How will change the code ?
If you are unable to get the value using PHP, try changing the value of the button's name on page load
Here is the JQUERY
$(document).ready(function){
$('div.akeebasubs-awesome-description').each(function(
substription = $(this).children('H4').html()
button = $(this).parent().next().children('button')
$(button).attr(name,substription.split(' ')[0]+'month')
})
})
and the JAVASCRIPT
divs = document.getElementsByClassName('akeebasubs-awesome-description');
for (var i in divs){
divs[i].parentElement.nextElementSibling.children[0].name = divs[i].children[0].innerHTML.split(' ')[0] + 'month'
}
This will take the text of the H4 and make that the corresponding button's name