Jump to content

[SOLVED] unwanted notice


squiblo

Recommended Posts

with this code, if the user is not logged in, i get this notice...

Notice: Undefined index: mycompany in /customers/squiblo.com/squiblo.com/httpd.www/index.php on line 245

 

this is the code...

<?php

include("checklogin.php");

$company = $_SESSION['mycompany'];

$query = mysql_query("SELECT * FROM members WHERE username='$company'");
if (mysql_num_rows($query)==0){
   die;
}else{
   $row = mysql_fetch_assoc($query);
   $location = $row['image'];
   if($location == ""){
      echo "<img src ='/profileimages/box.png' width='110' height='110' border='0'></a>";
   }else{
      echo "<img src ='$location' width='110' height='110' border='0'>";
   }
}


?>

Link to comment
https://forums.phpfreaks.com/topic/170911-solved-unwanted-notice/
Share on other sites

Okay, default_value was just a string I typed in. You could then substitute it with your own default value for $company if you had one. But if the script is working as intended, and you just want to get rid of the notice, change

 

$company = $_SESSION['mycompany'];

to

 

$company = isset($_SESSION['mycompany']) ? $_SESSION['mycompany'] : '';

or if you prefer the regular syntax:

 

if (isset($_SESSION['mycompany'])) {
$company = $_SESSION['mycompany'];
} else {
$company = '';
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.