This snippet is causing the file to throw a 500 erorr, and I cannot see why.
<head>
<?php
$link = mysql_connect('****', '***', '*****');
$db_selected = mysql_select_db('***', $link);
if (!$db_selected) {
echo 'error';
}
$adchan = $_COOKIE['adtail'];
$adarray = json_decode($adchan);
if($adarray->{'subcat'} != 'main'){
$sql = "SELECT term_id FROM wp_terms WHERE slug='$adarray->{'subcat'}'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$id = $row['term_id'];
$sql2 = "SELECT option_value FROM wp_10_options WHERE option_name='$id'";
$result2 = mysql_query($sql2);
while($row2 = mysql_fetch_array($result2))
{
echo "<meta http-equiv='Refresh' content='".$row2['option_value']."'>";
}
}
}
else{
$sql = "SELECT term_id FROM wp_terms WHERE slug='$adarray->{'cat'}'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$id = $row['term_id'];
$sql2 = "SELECT option_value FROM wp_options WHERE option_name='$id'";
$result2 = mysql_query($sql2);
while($row2 = mysql_fetch_array($result2))
{
echo "<meta http-equiv='Refresh' content='".$row2['option_value']."'>";
}
}
}
?>
</head>
Can anyone see why?
UPDATE
<?php
error_reporting(-1);
$adchan = $_COOKIE['adtail'];
$adarray = json_decode($adchan);
var_dump($adarray);
print $adarray['cat'];
?>
It runs fine until the the print, which is when I get the 500 error. the output is:
object(stdClass)#1 (4) { ["cat"]=> string(9) "lifestyle" ["subcat"]=> string(12) "arts-culture" ["page"]=> string(4) "main" ["zone"]=> string(22) "lifestyle/arts-culture" }
I’m not sure. But, it may because
mysql_fetch_arraycascade. You putmysql_fetch_arrayinside anothermysql_fetch_array.And assume it works, but it will give you bad performance.
This may be better for you. (In the inside of if part)