View Full Version : Improvement Suggestions Anyone?

02-14-2008, 06:22 PM
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.

02-15-2008, 09:32 AM
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 if ($statusNum == "") echo(" selected"); ?>

Nor do you need ( )'s around echos:

<?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 if ($statusNum == "") echo 'selected'; ?>

if you made your states an array, you could do something like this:

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.

02-15-2008, 04:33 PM
Thanks for the suggestions. I work on these and repost the update. I appreciate your input.

02-16-2008, 12:52 AM
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.