ROCKSTAR Posted February 26, 2008 Share Posted February 26, 2008 Hey guys, I'm new to PHP, recently evolved from ASP. I'm trying to get to grips with some of the differences and have come across a problem. I've a few area's on a page that display (or don't) depending on the query string but I keep getting errors. For example, if a record is updated in a database I return to the page with something like ?add=ok so that the page can display the message "Record Updated" which works fine, however when I simply visit the page without updating I get the following error: Notice: Undefined index: add in e:\yada yada yada\index.php on line 152 I know in ASP it would simply ignore the fact that it was empty and wouldn't display anything (the result I was hoping for here) but this doesnt seem to like the fact its not been given a value - I've tried a few tutorial sites but none of them go into this type of detail regarding IF statements or the QueryString. The code I'm using is; <? if($_GET['add'] == "ok") { echo "<span class='Text-Red'>- Record Added</span>"; } ?> Can someone point me in the right direction? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
dbo Posted February 26, 2008 Share Posted February 26, 2008 <? if( isset($_GET['add'] && $_GET['add'] == "ok") { echo "<span class='Text-Red'>- Record Added</span>"; } ?> Quote Link to comment Share on other sites More sharing options...
ROCKSTAR Posted February 26, 2008 Author Share Posted February 26, 2008 Thanks for the ridiculously quick reply! PHP really is better in all areas! Would I be right in thinking that the below would work for another section of the page I'm using the querystring that checks for an id (for editing records, using the id in a lookup); if( isset($_GET['id'] && $_GET['id'] != "") So, if it gets an id then I'll do a lookup. Thanks again for the quicky reply and baring with my level of n00bness.. Quote Link to comment Share on other sites More sharing options...
dbo Posted February 26, 2008 Share Posted February 26, 2008 I'd have to see exactly what it is you're doing, but: if( isset($_GET['id'] && $_GET['id'] != "") Should be: if( isset($_GET['id']) && $_GET['id'] != "" ) { } However, instead of using != "" it might be more appropriate to determine if it's an integer or not. It depends on your data model, but make sure you are forcing people to play by your rules so that you can avoid being haxored. Quote Link to comment Share on other sites More sharing options...
ROCKSTAR Posted February 27, 2008 Author Share Posted February 27, 2008 Cheers, I've got it working although the page doesnt always like me using this multiple times on the same page. The page has add, update and an image upload script on it, each one with a little snip of code just to say "record added" or "updated" or "uploaded". The common error I get is "," or ")" expected but I'm sure all the code is closed off correctly. I managed a work-around anyway so thanks for all the help but if there is a different way for doing this sort of thing multiple times please let me know? Thanks again. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.