'Notice: Undefined index' after turning errors up to full

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
deejay
Forum Contributor
Posts: 201
Joined: Wed Jan 22, 2003 3:33 am
Location: Cornwall

'Notice: Undefined index' after turning errors up to full

Post by deejay »

Hi

I have made a few forms that write data to mySQL, these seem to work fine by all accounts but after turning errors to full I get the error
Notice: Undefined variable: submit in "address" in line 31
line 31 is

Code: Select all

<?php
if ($submit) {

?>
i have also tried $_POST['submit'] . i also have similar forms wrapped in a function that dont give me any error, so I take it that it there another way of defining the value $submit that I need to do.

Thanks
User avatar
d1223m
Forum Commoner
Posts: 80
Joined: Mon Mar 31, 2003 5:15 am
Location: UK, West Sussex

Post by d1223m »

it just means that the variable $submit has not been initialised yet.
this probably happens on the first view of the page before you have pressed the submit button.

it is much better to use $_POST['submit'] as you should not turn on register_globals. consult the manual for reasons.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Instead of doing

Code: Select all

if ($submit) {
for testing for the existence of a variable you should be using isset() or empty()
and as d1223m said, use $_POST, register_globals is deprecated.

Mac
User avatar
deejay
Forum Contributor
Posts: 201
Joined: Wed Jan 22, 2003 3:33 am
Location: Cornwall

Post by deejay »

cheers :) once again.
Post Reply