Hi David
Hope you're keeping well and busy.
We are in process of moving to a new server with only PHP5 installed and are getting this error in connection to a mod we added from you a while back for price min and max search
Notice: Undefined index: minPrice in
/var/www/vhosts/domain.com/httpdocs/productsearch/beautyshops/search.php on line 13
Notice: Undefined index: maxPrice in
/var/www/vhosts/domain.com/httpdocs/productsearch/beautyshops/search.php on line 15
The code in search.php is
{code saved}
Could you take a look please
Chris
That worked great thanks David
Could you also take a look at:
Notice: Undefined variable: count in
/var/www/vhosts/domain.com/httpdocs/productsearch/beautyshops/html/featured.php on line 46
<?php
if ($count++ == 2)
{
print "</tr><tr>";
$count = 0;
}
?>
and
Notice: Undefined variable: maxPrice in
/var/www/vhosts/domain.com/httpdocs/productsearch/beautyshops/html/searchform.php on line 58
<input type='text' name='maxPrice' size='5' value='<?php print ($maxPrice?$maxPrice:""); ?>'
Chris
Hi,
For your mod in html/featured.php; add the following code at the top of the script (the warning message is because the variable has not been initialised):
$count = 0;
In html/searchform.php, edit that line as follows:
<input type='text' name='maxPrice' size='5' value='<?php print (isset($maxPrice)?$maxPrice:""); ?>'
Cheers,
David.
Hi David
Many thanks that nearly sorted that out.
The first min max price mod worked to remove the error warning but now seems to set the min price to zero and the max price to zero resulting in no results for any search entered. Do you have any ideas what might be causing that.
Chris
Hi Chris,
Looking at the code; the following is probably more appropriate as it looks like the variable may be set; just set to empty; so it is still using sprintf resulting in a value of "0.00"; which when used in a test returns TRUE in PHP.
Try this block as a replacement:
$minPrice = ((isset($_GET["minPrice"])&&($_GET["minPrice"]>0))?sprintf("%.2f",$_GET["minPrice"]):"");
$maxPrice = ((isset($_GET["maxPrice"])&&($_GET["maxPrice"]>0))?sprintf("%.2f",$_GET["maxPrice"]):"");
Cheers,
David.
Hi David
That worked great, I think we're all sorted now.
Many thanks
Chris
Just trying out the new PT version on my localhost and had the same problem as chrisst1 (Undefined index for minPrice and maxPrice). The mod on this page made the error go away (thanks!)
I also get this error regarding priceWhere:
Notice: Undefined index: minPrice in Z:\wamp\www\ptnew\search.php on line 14
Notice: Undefined index: maxPrice in Z:\wamp\www\ptnew\search.php on line 16
<b>Notice: Undefined variable: priceWhere in Z:\wamp\www\ptnew\search.php on line 157
Notice: Undefined variable: priceWhere in Z:\wamp\www\ptnew\search.php on line 159</b>
any ideas?
Hi Jim,
That makes sense; to suppress all warnings; looking at the unmodified search.php for the following block of code between lines 14 and 32:
$minPrice = ($_GET["minPrice"]?sprintf("%.2f",$_GET["minPrice"]):"");
$maxPrice = ($_GET["maxPrice"]?sprintf("%.2f",$_GET["maxPrice"]):"");
if ($minPrice || $maxPrice)
{
if ($minPrice && $maxPrice)
{
$priceWhere = " AND price BETWEEN '".$minPrice."' AND '".$maxPrice."' ";
}
elseif ($minPrice)
{
$priceWhere = " AND price > '".$minPrice."' ";
}
elseif ($maxPrice)
{
$priceWhere = " AND price < '".$maxPrice."' ";
}
}
...and REPLACE that with:
if (isset($_GET["minPrice"]))
{
$minPrice = sprintf("%.2f",$_GET["minPrice"]);
}
else
{
$minPrice = "";
}
if (isset($_GET["maxPrice"]))
{
$maxPrice = sprintf("%.2f",$_GET["maxPrice"]);
}
else
{
$maxPrice = "";
}
if ($minPrice || $maxPrice)
{
if ($minPrice && $maxPrice)
{
$priceWhere = " AND price BETWEEN '".$minPrice."' AND '".$maxPrice."' ";
}
elseif ($minPrice)
{
$priceWhere = " AND price > '".$minPrice."' ";
}
elseif ($maxPrice)
{
$priceWhere = " AND price < '".$maxPrice."' ";
}
}
else
{
$priceWhere = "";
}
Cheers,
David.
this new code gives me an error:
Parse error: parse error in Z:\wamp\www\ptnew\search.php on line 25
line 25 is:
if (isset())
Hi Jim
Sorry about that - it should be:
if (isset($_GET["maxPrice"]))
(correct above also)
Cheers,
David.
Hi Jim,
It is because of the PHP warning level being set to the maximum in your configuration; in the mean time the easiest thing to do; rather than changing all the code would be to add the following line at the top of config.php:
error_reporting("E_ERROR");
Cheers,
David.
Hi Chris,
This just means that PHP is configured slightly differently on your new server; with a higher
warning level, which is why you are getting the undefined index message.
Without editing your php.ini, you could correct this in the code by changing the following
code (starting at line 13 in your search.php):
$minPrice = ($_GET["minPrice"]?sprintf("%.2f",$_GET["minPrice"]):"");
$maxPrice = ($_GET["maxPrice"]?sprintf("%.2f",$_GET["maxPrice"]):"");
to:
$minPrice = (isset($_GET["minPrice"])?sprintf("%.2f",$_GET["minPrice"]):"");
$maxPrice = (isset($_GET["maxPrice"])?sprintf("%.2f",$_GET["maxPrice"]):"");
That should do the trick!
Cheers,
David.