Jump to content


Photo

Post Array With Undefined Indexes?


  • Please log in to reply
3 replies to this topic

#1 dksmarte

dksmarte
  • Members
  • Pip
  • Newbie
  • 2 posts

Posted 02 March 2006 - 01:49 AM

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:

<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>
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?
[url=http://dksmarte.freelinuxhost.com][/url]

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 02 March 2006 - 02:03 AM

[!--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.

#3 dksmarte

dksmarte
  • Members
  • Pip
  • Newbie
  • 2 posts

Posted 02 March 2006 - 02:05 AM

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) View Post[/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.
[url=http://dksmarte.freelinuxhost.com][/url]

#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 02 March 2006 - 02:06 AM

Still, its poor practice to not check these things are set before using them. Anyway..... up to you.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users