English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I get this error in this code:

Error:
Notice: Undefined index: do in C:\Documents and Settings\me\Desktop\php examp\php38.tmp on line 4

Code:


$do=$_GET['do'];
if ($do == 'send') {
$name= $_POST['name'];
$comments= $_POST['comments'];
$check= $_POST['check'];
$which= $_POST['which'];
$what= $_POST['what'];
} else { ?>


Name:

Comments:


check this

1
2





?>

2006-06-24 04:46:21 · 3 answers · asked by QuestionAnswer 2 in Computers & Internet Programming & Design

3 answers

Remember when you FIRST enter the page, there is no such thing about the variable $do since $_POST array does not exist!

I see multiple problems over there.
- Your form has the method of POST, so why do you use GET ?
+ $do=$_GET['do']; should be $do=$_POST['do'];
- Now since the variable do does not exist you could do a simple if statement that checks that. The function isset checks if that variable exists.
+ $do = isset($_POST['do']) ? 'send' : 'ok';
- But there is another problem, The hidden name for do does not exist.. So lets change it to do
+

[now the overall code]
=============================



// Lets initialize the variable
$do = isset($_POST['do']) ? 'send' : 'ok';

// Lets just display the current Action
echo 'ACTION:'.$do;

// Check if the hidden variable was sent
if ($do == 'send') {

// Lets print out the post array
var_dump($_POST);

} else { ?>








=============================
I took out the other forms...

The above should work.. Now.. But why introduce another variable if you already have the submit variable intact? What you could do is say $do = isset($_POST['submit']) ? 'send' : 'Submit'; That will remove that hidden field. Another thing I realize is that your mixing HTML code with PHP code which is BAD PRACTICE. I recommend you to at least separate them, or if you don't want to use a templating engine, I recommend you do at least store the output in one variable like outvar = "". That will take out alot of issues in the future.

Anyways.. Good Luck

2006-06-24 07:27:54 · answer #1 · answered by ? 6 · 0 0

Oh yeah i can definately see the problem now, youre using PHP... dont.

2006-06-24 18:18:16 · answer #2 · answered by Shweet! 1 · 0 0

if I change the form tag to this I get no errors.

2006-06-24 12:04:31 · answer #3 · answered by fwiiw 4 · 0 0

fedest.com, questions and answers