Jump to content

Archived

This topic is now archived and is closed to further replies.

dksmarte

Post Array With Undefined Indexes?

Recommended Posts

I'm making a simple script to add a member to a website and I got some pretty interesting errors. First of all, here's the code:

*removed because no longer relevant to solution*

Here's the HTML form that submits to the above code:

[code]<form action="addmember.php" action="post">
                        <table>
                            <tr>
                                <td>Username:</td>
                                <td><input type="text" name="username" /></td>
                            </tr>
                            <tr>
                                <td>MD5 Hash Of Password:</td>
                                <td><input type="text" name="password" /></td>
                            </tr>
                            <tr>
                                <td></td>
                                <td><input type="submit" value="Add Member" /></td>
                            </tr>
                        </table>
                    </form>[/code]
I get this error when creating a new member with the above forum on php page:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
Notice: Undefined index: username in c:\program files\easyphp1-8\www\haven\members\addmember.php on line 13

Notice: Undefined index: password in c:\program files\easyphp1-8\www\haven\members\addmember.php on line 14[/quote]

Now I know that I should check to make sure that the values of the script are never empty but I'm not too concerned with that since this script can only be accessed by administrators. Anyways, even when I submit data from the form so I know that the post array will have the indexes username and password defined, it still gives me that error. Shouldn't it be working? What am I missing?

Share this post


Link to post
Share on other sites
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Now I know that I should check to make sure that the values of the script are never empty but I'm not too concerned with that[/quote]
If you know you should do something, why dont you do it? If the form is posted empty then the indexes are never created.

Share this post


Link to post
Share on other sites
Nevermind. I realized what the problem was. I put action="addmember.php" and action="post" in the form tag. It should've been method="post".

[!--quoteo(post=350850:date=Mar 1 2006, 09:03 PM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Mar 1 2006, 09:03 PM) [snapback]350850[/snapback][/div][div class=\'quotemain\'][!--quotec--]
If you know you should do something, why dont you do it? If the form is posted empty then the indexes are never created.
[/quote]
Well I was purposefully submitting things so that I knew the indexes would be created. That's why I found the error so weird when I got it. No worries though, I found the problem in my form.

Share this post


Link to post
Share on other sites
Still, its poor practice to not check these things are set before using them. Anyway..... up to you.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.