Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    69
    Thanks
    11
    Thanked 2 Times in 2 Posts

    Improvement Suggestions Anyone?

    I have a login form that will create a new user in our member management system. It works, but wanted to see if anyone could help me improve it. I am no expert and am sure there some things i could do better.

    The form data is sent to the back to the same page and has a hyperlink variable in order to know to process. Once the form is submitted, the data is validated, which includes a fake login for that user to test whether or not the user exists. If no errors occur through validation, the individual is created by creating a new household with that person in it. The script then logs the individual in in order to get the just assigned icode from fellowship one that will be used later.

    I have attached the file, just change it from .txt to .php

    Thanks again for any help.
    Attached Files Attached Files

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    Oregon, United States of America
    Posts
    882
    Thanks
    1
    Thanked 9 Times in 9 Posts
    There are a lot of things that could be cleaned up and changed, but you'll get different opinions from different people.

    You don't need semi-colons after }'s And you don't need any { } for single lines. See below:

    PHP Code:
    <?php if ($statusNum == "") echo(" selected"); ?>
    Nor do you need ( )'s around echos:
    PHP Code:
    <?php if ($statusNum == "") echo " selected"?>
    And you shouldn't use double quotes in an echo or print unless you have variables in the string. It slows it down:

    PHP Code:
    <?php if ($statusNum == "") echo 'selected'?>
    if you made your states an array, you could do something like this:
    PHP Code:
    for( $i=0$i<count($states); $i++ ){
        echo 
    '<option value="'.$states[$i].'"'.(($state==$states[$i])?' selected':'').'>'.$states[$i].'</option>';

    I have had some really bad experiences with posting to the same file. Post to a different file, and use sessions to hold your post data and errors should you need to go back and display an error. There are a lot of reasons for this, but consider these:

    The user submits, and the page comes up with errors on it. for some reason the user hits the back button to make those changes... now that post data is gone unless they hit forward.

    The user submits, and then clicks some link or something, and ends up having to go back to the page, (maybe they hit refresh.) They are then prompted to resend the post data. if they choose not to, the information is gone.

    The user submits, and everything works great. They hit the back button and resend the post data, and then the information is sent again. Repeat x1000

    A lot of the problems with posting to the same page are "Why would a user ever do that" kind of problem, but it DOES happen. I am building the second problem of a very large web application for a company now. The first version uses this same self posting technique. My users love to hit the back button as an undo, or the forward as a redo, or refresh if something they expected to see didn't appear. Any of those can ruin your post data. Use sessions. Thats what their for.
    If I'm postin here, I NEED YOUR HELP!!

  • Users who have thanked Ultragames for this post:

    michaelespinosa (02-15-2008)

  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    69
    Thanks
    11
    Thanked 2 Times in 2 Posts
    Thanks for the suggestions. I work on these and repost the update. I appreciate your input.

  • #4
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    Pratically every set of coding guidelines invented will reccomend using {}s regardless of how many lines there are, it prevents errors creeping in when someone decided two things actually need doing.
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •