1 kskhater Jan 27, 2007 05:50
3 kskhater Jan 27, 2007 06:24
Sorry EdB if I don't get it. Do mean for example I could do this:
if( $_GET['p'] exists) {
p = "Undefined index: p in /home/alkha4/public_html/blog/addOns/friend/friend.php on line 59";
} else {
p = 0
}
It does seem right, does it?
4 edb Jan 27, 2007 06:27
No not at all. I have a similar problem to your problem. All I care about is not displaying the notice, but, would prefer to have good code. Unfortunately I do not know what the proper way to code it would be.
5 balupton Jan 27, 2007 12:49
Use:
$param = isset($_GET['param']) ? $_GET['param'] : NULL; // where NULL is your default value
The reasoning behind the notice is that you are trying to access a part of a array that doesn't exist, which should be avoided, hence the isset. The format of it is called a conditional statement (or at least that's what i know it as...) it means
$var = condition ? value if true : value if false;
Good? I think this is included within the coding guidelines page for b2evolution, i will check it now and add it if needed.
6 kskhater Jan 27, 2007 15:20
Thanks balupton, this works just perfect.
I hope EdB sees this.
7 kskhater Jan 27, 2007 15:39
Sorry balupton, I did not check if the hack was doing the right thing, only I noticed that it was not giving notice's. Actually, all the variables return NULL. Before the variables return the right values but gave notices as I mentioned above.
8 balupton Jan 27, 2007 16:10
all the other things you are using are POST maybe the ones you are using GET for are meant to be POST?
9 kskhater Jan 27, 2007 16:19
No. it used work just fine before with 0.9.1
Here is a bigger portion of that code:
$p = isset($_GET['p']) ? $_GET['p'] : NULL; // where NULL is your default value
$id = isset($_GET['id']) ? $_GET['id'] : NULL; // where NULL is your default value
// $link = str_replace(" ","+", $link); // get rid of any spaces
if(!isset($_POST['action']) || $_POST['action'] == ""){
printpage("","","","","","","","");
}
else if($_POST['action'] == "submit"){
$send = true;
function is_valid_email($sender_mail) {
if(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $sender_mail)) {
return 0;
} else {
return 1;
}
}
$sender_mail = $_POST['sender_mail'];
$friend_mail = $_POST['friend_mail'];
$sender_name = $_POST['sender_name']; $sender_name=ucfirst($sender_name);
$sendall = isset($_GET['send_pos']) ? $_GET['send_pos'] : NULL; // where NULL is your default value
$opt_msg = $_POST['opt_msg'];
$link = isset($_GET['link']) ? $_GET['link'] : NULL; // where NULL is your default value
$js = $_POST['js'];
$id = $_POST['id'];
$p = $_POST['p'];
As you can see for example there is $_GET('id') and $_POST('id')
10 balupton Jan 27, 2007 16:31
well just do this
echo '<pre>';
echo '$_GET :';
var_export($_GET);
echo '$_POST:';
var_export($_POST);
echo '</pre>';
And that will show you what your variables are
11 kskhater Jan 27, 2007 16:41
I did that and I get all the variables with the right values. It is only those notice's that are nuisance.
12 kskhater Jan 27, 2007 19:33
Sorry again. It works just fine. I made a mistake before.
Instead of this:
$id = isset($_GET['id']) ? $_GET['id'] : NULL; // where NULL is your default value
It should be:
$link = isset($_GET['id']) ? $_GET['id'] : NULL; // where NULL is your default value
13 edb Jan 27, 2007 22:39
Thanks balupton! That worked rather nicely.
14 balupton Jan 27, 2007 22:40
:)
15 stk Jan 28, 2007 00:26
I recognize that code :p
Thanks for the explanation, Balupton. :D (Now all I have to do, is REMEMBER to use it).
I'm having a similar problem with a _GET in a plugin. When it's a new post there is no post_ID to get, so it gives me the undefined index message. I'm pretty sure my plugin works, so I'd be happy just suppressing the Notice message. Ideally I'd be able to do something like
BTW this bit of the plugin worked fine in 1.8.6 but is throwing the Notice now that I'm using it on a 1.9.2 installation.