Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 05-18-2009, 02:16 PM php Undefined index
Knight13's Avatar
Defies a Status

Posts: 10,289
Name: Knight13
Location: Cleveland, Ohio
Trades: 0
I am trying to figure out how to make a paging script and the section of code below is from a code that i am learning it from now when i put this code in my test page it gives me the following error.Notice: Undefined index: start in C:\wamp\www\firstpage.php on line 3

and i do not understand why i am getting his error and i do not understand how to fix it any help would be appreciated.

~~~this is the actual code snippet~~~
PHP Code:
 <?php
$pagesize 
10;
$start = (int)$_GET['start'];
$start = (isset($_GET['start'])) ? $start 0;
?>

Last edited by Knight13; 05-18-2009 at 02:23 PM..
Knight13 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-18-2009, 02:38 PM Re: php Undefined index
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Do you have strict error reporting on? The code you wrote should work even though you get the notice. This should accomplish the same thing without the notice:

PHP Code:
<?php
$pagesize 
10;
$start = (isset($_GET['start'])) ? $_GET['start'] : 0;
?>
This will not cause a notice because if $_GET['start'] is not set, you never try to access it.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 05-18-2009, 02:51 PM Re: php Undefined index
Knight13's Avatar
Defies a Status

Posts: 10,289
Name: Knight13
Location: Cleveland, Ohio
Trades: 0
my error reporting is on E_ALL and the code does work i just get that notice warning, is that warning something i can suppress with the @ symbol or is it something i need to fix?
Knight13 is offline
Reply With Quote
View Public Profile
 
Old 05-18-2009, 03:08 PM Re: php Undefined index
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
The default is E_ALL & ~E_NOTICE (everything except notices). Suppressing the line would work, but ideally you don't want to suppress lines unless you have to. Personally, I don't like throwing error messages away. You may want to look into custom error handlers so you can choose how to deal with error messages. This allows you to track the errors your users get without giving them the error message.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 05-18-2009, 03:26 PM Re: php Undefined index
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Matt's right. I admit to being lazy. Notices shouldn't be on (in my never humble opinion) on a live server. However, best practices being followed means it won't matter and that's what Matt is suggesting. PHP let's you do a lot without requiring academic-level formality, but with notices on, you are expected to be more rigorous. If I were you, I'd use Matt's code with 1 modification I'm sure he just overlooked:

PHP Code:
<?php 
$pagesize 
10
$start = (isset($_GET['start'])) ? (int)$_GET['start'] : 0
?>
Then, everywhere else in your code, you'll want to be very careful about ensuring that you're abiding by all the best practices (no, I don't have a list ).

Lazy 'ole me just turns off notices.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 05-19-2009, 03:30 AM Re: php Undefined index
Knight13's Avatar
Defies a Status

Posts: 10,289
Name: Knight13
Location: Cleveland, Ohio
Trades: 0
Sorry that i do not understand guys but are you saying that notices are unimportant and that is why i should turn them off?

I am still fairly new at php and i do not want to get into a position where i am writing bad code,

but if notices are just minor things that do not ever effect a php script then i will turn the notices off because i am always getting notices like that.
Knight13 is offline
Reply With Quote
View Public Profile
 
Old 05-19-2009, 03:45 AM Re: php Undefined index
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Notices will typically inform you of problems with your method. Most of the time they don't indicate that your script isn't working as intended. If you're not working on a live site, leaving them on couldn't hurt. A lot of things PHP generate notices for would cause an error in a more strict language. In addition to that I assume a script with no notices would be more effecient than an equivalent one with them.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 05-19-2009, 04:03 AM Re: php Undefined index
Knight13's Avatar
Defies a Status

Posts: 10,289
Name: Knight13
Location: Cleveland, Ohio
Trades: 0
Ok thanks alot guys.
Knight13 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to php Undefined index
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.27597 seconds with 12 queries