Current location: Hot Scripts Forums » Programming Languages » PHP » ERROR - Notice: Undefined index: - ERROR


ERROR - Notice: Undefined index: - ERROR

Reply
  #1 (permalink)  
Old 11-09-08, 08:58 PM
tommyc325's Avatar
tommyc325 tommyc325 is offline
Wannabe Coder
 
Join Date: Sep 2005
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Cool ERROR - Notice: Undefined index: - ERROR

Im doing a simple ifelse statement and im getting these errors.


Notice: Undefined index: alert in /var/www/vhosts/videostatus.com/httpdocs/dev/cp/cp_videos.php on line 194

Notice: Undefined index: alert in /var/www/vhosts/videostatus.com/httpdocs/dev/cp/cp_videos.php on line 198

Notice: Undefined index: alert in /var/www/vhosts/videostatus.com/httpdocs/dev/cp/cp_videos.php on line 202


PHP Code:

 if($_GET['alert'] == "update")

    
    echo 
"<br /><span class=error>Your video has been updated.<br></span>";

    elseif(
$_GET['alert'] == "add")
    
    echo 
"<br /><span class=error>Your video has been added.<br></span>";
    
    elseif(
$_GET['alert'] == "delete")
    
    echo 
"<br /><span class=error>Your video has been deleted.<br></span>"
i dont see any issues here - please help
Reply With Quote
  #2 (permalink)  
Old 11-10-08, 02:06 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
$_GET['alert'] is not set (undefined). Use isset() in your is/elseif conditions, or set it to a default value at the beginning of your code.
Reply With Quote
  #3 (permalink)  
Old 11-10-08, 08:19 AM
tommyc325's Avatar
tommyc325 tommyc325 is offline
Wannabe Coder
 
Join Date: Sep 2005
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
i tried setting the variable alert at the beginning of my code and im still get the same errors.

$alert = "";

Last edited by tommyc325; 11-10-08 at 08:24 AM.
Reply With Quote
  #4 (permalink)  
Old 11-10-08, 09:08 AM
Zefer's Avatar
Zefer Zefer is offline
Wannabe Coder
 
Join Date: May 2007
Posts: 190
Thanks: 2
Thanked 0 Times in 0 Posts
Try this:
PHP Code:

<?php
$alert 
$_GET["alert"];
switch (
$alert) {
 case 
'update':
  echo 
"<br /><span class=error>Your video has been updated.<br></span>";
 break;
 case 
'add':
  echo 
"<br /><span class=error>Your video has been added.<br></span>";
 break;
 case 
'delete':
  echo 
"<br /><span class=error>Your video has been deleted.<br></span>";
 break;
};
?>
Reply With Quote
  #5 (permalink)  
Old 11-10-08, 09:13 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Or:
PHP Code:

$alert = isset($_GET["alert"]) ? $_GET['alert'] : null
Reply With Quote
  #6 (permalink)  
Old 11-11-08, 06:40 PM
tommyc325's Avatar
tommyc325 tommyc325 is offline
Wannabe Coder
 
Join Date: Sep 2005
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Zefer and Nico thanks again.


Nico i used your variable instead of Zefer's and that worked great can you explain this to me a little bit

im confused with the "?" and the ": null"

thanks
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ and MSSQL tutorials? scott2500uk C/C++ 8 05-11-09 02:33 AM
[SOLVED] No page no error? Hamed PHP 11 07-19-08 12:39 AM
Syntax Error Nikas Database 4 05-15-08 10:48 AM
No error message... stormshadow PHP 3 12-11-06 06:31 PM
Undefined index error. Need help. sondogg PHP 3 03-15-06 07:14 PM


All times are GMT -5. The time now is 08:24 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.