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
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 = '';
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.