Page 1 of 1

[SOLVED] Notice: Undefined index: error

Posted: Wed Oct 19, 2005 12:15 pm
by FREESTYLER
made my first project in php
actuly change it from java to php to run on our hosts site.
getting some errors
cant figure out why?
Heres the site
http://www.datainfinity.com/tmp/maplinks.php

and heres the code

line 50:

Code: Select all

if ($_GET['add'] == 'Add')
    {
    $insert =" INSERT INTO maplinks (name, url, description) " . " VALUES('" . $_GET['name'] . "','" . $_GET['url'] . "','" . $_GET['description'] . "') ";
    $results=mysql_query($insert) or die('could not submit query ' . mysql_error());
    }
lines 56, and 62 are the same with diffrent GET parameters (edit and delete)

i know this isnt the most efficent way but i started learning php last night.
thanks guys
Neill

Posted: Wed Oct 19, 2005 6:28 pm
by Ambush Commander
You have E_ALL error reporting. Try making sure variables exist before trying to get their value.

Posted: Wed Oct 19, 2005 6:33 pm
by Charles256
yeah,just do

Code: Select all

if (isset($variable)
{
pertinent code here
}
before you actually use every variable.that'll get rid of those notices:-D

Posted: Wed Oct 19, 2005 6:35 pm
by Ambush Commander
(missing parentheses)

Ternary operator is often quicker:

Code: Select all

$variable = isset($array['key']) ? $array['key'] : 'some default value';

Posted: Wed Oct 19, 2005 6:36 pm
by Charles256
true but to me it's not nearly as readable...but that's just one of those personal preference things... :-D

Posted: Wed Oct 19, 2005 11:59 pm
by FREESTYLER
Charles256 wrote:yeah,just do

Code: Select all

if (isset($variable)
{
pertinent code here
}
before you actually use every variable.that'll get rid of those notices:-D
i tried this way and it got rid of my errors but also when i sent it a GET request it would not pick it up, so i couldnt add, edit or delete any of my entries?

Posted: Thu Oct 20, 2005 12:16 am
by Charles256
actually do...

Code: Select all

if(isset($_REQUEST['variablename']))
{
blah
}
that should fix ya up

Posted: Thu Oct 20, 2005 12:28 am
by FREESTYLER
Cheers Charles256
that fixed it up
thanks for your help