0

I am getting this error on my test server but not on the godaddy server.

Notice: Undefined index: admin in /Applications/XAMPP/xamppfiles/htdocs/test_new/specials.php on line 24

<?php
$page = current(split("\.", substr($_SERVER['SCRIPT_NAME'], 1)));

$x = mysql_query("select * from specials where id in (select id from specials_pages where page='$page')");
while ($y = mysql_fetch_array($x))
{
    $y['text'] = str_replace("\n", "<br/>", $y['text']);

    if ($y['car_id'] > 0)
    {
        $x = mysql_query("select id from images where car_id=" . $y['car_id'] . " and main=1");
        $picId = @end(mysql_fetch_array($x, MYSQL_ASSOC));
if (!empty($picId)) {       
?>
            <a href="viewcar.php?id=<?=$y['car_id']?>"><img border=0 src="images/vehicles/<?=$y['car_id']?>-<?=$picId?>.jpg" width=226 style="margin-bottom: 10px;"></a>
        <?php }
    }
    ?>
    <div <?php if ($_SESSION['admin'] == "1") { ?>onclick="javascript:location='admin/addspecials.php?id=<?=$y['id']?>';"<?php } ?> class="special" style="margin-bottom: 10px; background: #<?=$y['bgcolor']?>; color: #<?=$y['color']?>;"><?=$y['text']?></div>
    <?php
}
?>
<?php if ($_SESSION['admin'] == "1") { ?><a style="color: white;" href="admin/addspecials.php">Add special</a><?php } ?>

line 24 is so that when you are logged in as an admin to the site you would see the link to add a special. This is a live website that works on godaddy. I have it on my test server making changes to it and I get the error. Is there anything I'm missing?

This is line 24

if ($_SESSION['admin'] == "1") { ?><a style="color: white;" href="admin/addspecials.php">Add special</a><?php }
  • 1
    Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Feb 03 '16 at 22:26
  • Check if `$_SESSION['admin']` is set first. Your godaddy server might have display errors turned off; or the `SESSION` might be set there. – chris85 Feb 03 '16 at 22:28
  • Thank you. I appreciate that. This site wasn't written by me. I took it over. I thank you for that information. – Albert Anderson Feb 03 '16 at 22:29
  • @AlbertAnderson You see the notice on your server but not at godaddy due to a different `error_reporting` set. Your is a good set: locally you can see errors and notices, remotely not. In this case, the $_SESSION['admin'] is not yet defined and php notice you about that. Although your code works (usually notices don't cause big problems), for a very-super-clear style, you have to pre-check `$_SESSION[admin]` using `if( isset( $_SESSION['admin'] ) )` – fusion3k Feb 03 '16 at 22:43

0 Answers0