Page 5 of 6
Re: Undefined variable - why am I getting these?
Posted: Thu Jan 23, 2014 11:16 am
by simonmlewis
So how do I get around it?
The page is designed where the person reaches the page and is then asked to enter a price range.
I would have put this into a script that only uses it when something is posted, but that is what the SESSION is for, so it can go page by page.
Re: Undefined variable - why am I getting these?
Posted: Thu Jan 23, 2014 11:29 am
by Celauran
Code: Select all
$pricemin = 0;
if (isset($_POST['pricemin'])) {
$pricemin = $_POST['pricemin'];
} else if (isset($_SESSION['pricemin'])) {
$pricemin = $_SESSION['pricemin'];
}
// Now let's store it in session data
$_SESSION['pricemin'] = $pricemin;
Re: Undefined variable - why am I getting these?
Posted: Fri Feb 14, 2014 9:09 am
by simonmlewis
Code: Select all
$loadout_recalc = $price1calc + $price2calc + $price3calc + $price4calc + $price5calc + $price6calc + $price7calc + $price8calc + $price9calc + $price10calc;
I am getting an error on this - the usual:
[text]Notice: Undefined variable: price8calc in C:\xampp\phpMyAdmin\site\includes\loadout.inc on line 1135[/text]
Clearly it's because $price8calc doesn't have anything in it. But how do I do that calculation, without getting that error?
Re: Undefined variable - why am I getting these?
Posted: Fri Feb 14, 2014 9:15 am
by Celauran
Initialize them all with a value of 0?
Re: Undefined variable - why am I getting these?
Posted: Fri Feb 14, 2014 9:18 am
by simonmlewis
Blimey it's obvious when someone tells you!!
Thanks.
Re: Undefined variable - why am I getting these?
Posted: Tue Feb 18, 2014 10:51 am
by simonmlewis
Code: Select all
if (is_null($row->doc1) && ($row->doc2) && ($row->doc3))
{ echo " color:#ff0000";}
What's wrong with this?
The three fields all are set to NULL. So I thought the text should be shown as RED.
Re: Undefined variable - why am I getting these?
Posted: Tue Feb 18, 2014 10:53 am
by Celauran
You're only checking if the first one is null
Re: Undefined variable - why am I getting these?
Posted: Tue Feb 18, 2014 10:58 am
by simonmlewis
Code: Select all
if (is_null($row->doc1) && is_null($row->doc2) && is_null($row->doc3))
{ echo " color:#ff0000";}
??
Re: Undefined variable - why am I getting these?
Posted: Tue Feb 18, 2014 11:00 am
by simonmlewis

Cool - it works. Ta.
Re: Undefined variable - why am I getting these?
Posted: Tue Apr 08, 2014 3:07 am
by simonmlewis
What is wrong with this?
Code: Select all
if (strpos($_SERVER['HTTP_USER_AGENT'],'Firefox')!==FALSE) {
echo "<div style='clear: both;' /><br/><img src='/images/divider.png' /></div>";}
elseif (strpos($_SERVER['HTTP_USER_AGENT'],'Safari')!==FALSE) {
echo "<div style='clear: both;' /><br/><img src='/images/divider.png' /></div>";}
elseif (strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')!==FALSE) {
echo "<div style='clear: both;' /><br/><img src='/images/divider_ie.png' /></div>";}
else { echo "<div style='clear: both;' /><br/><img src='/images/divider_nogap.png' /></div>";}
We are getting dozens of errors like this:
[text][Mon Apr 07 17:41:30 2014] [error] [client 50.28.34.45] PHP Notice: Undefined index: HTTP_USER_AGENT in /var/www/vhosts/site.co.uk/httpdocs/includes/categ.inc on line 413[/text]
Line 413 is is the top line of that.
We are getting hundreds of these errors on other pages that use the same format of code.
Is that now incorrect coding to capture the user agent? Something is causing a massive amount of these errors.
Re: Undefined variable - why am I getting these?
Posted: Tue Apr 08, 2014 7:23 am
by Celauran
It's not a required header, so it's possible not all requests contain it. Like all undefined index notices, just check if the array key exists before trying to use it.
Re: Undefined variable - why am I getting these?
Posted: Tue Apr 08, 2014 7:39 am
by simonmlewis
Sorry how do you mean? I need to see what the browser is.
Re: Undefined variable - why am I getting these?
Posted: Tue Apr 08, 2014 8:47 am
by Celauran
Any browser or agent can choose not to send that information, so it may not always be set, and you may not always be able to tell what browser is making the current request. Nothing you can do about that.
Re: Undefined variable - why am I getting these?
Posted: Tue Apr 08, 2014 8:49 am
by simonmlewis
Gotchya.
So the large amount of errors we are now getting for this could be someone who is blocking it, or jsut using a browser that won't idenfity it. So I need to put the query into a variable and query the variable instead? if it is isset...??
Re: Undefined variable - why am I getting these?
Posted: Tue Apr 08, 2014 8:52 am
by simonmlewis
Actually, is this sufficient?
Code: Select all
$browsercheck = $_SERVER['HTTP_USER_AGENT'];
if(isset($browsercheck))
{
if (strpos($_SERVER['HTTP_USER_AGENT'],'Firefox')!==FALSE) {
echo "<div style='clear: both;' /><br/><img src='/images/divider.png' /></div>";}
elseif (strpos($_SERVER['HTTP_USER_AGENT'],'Safari')!==FALSE) {
echo "<div style='clear: both;' /><br/><img src='/images/divider.png' /></div>";}
elseif (strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')!==FALSE) {
echo "<div style='clear: both;' /><br/><img src='/images/divider_ie.png' /></div>";}
else { echo "<div style='clear: both;' /><br/><img src='/images/divider_nogap.png' /></div>";}
}