The order of things (PHP sendmail to database to profile login)

I’m not new to webdesign, but I’m very new to web development.

I’ve created a PHP registration form for a sports league website. That form works great and the emails are received by those who should receive them.

Here’s what else I’m trying to accomplish…

  1. Have the fields filled in on the registration form, filter to a MySQL database so that queries can be pulled by the site’s owner.

  2. Be able to have the registrant log back into the site and view his/her profile and be able to make adjustments at will.

I’m really not sure where to start. If you could break it down to me like I’m a 5 or 10 year old… that would be great. Any advice is likely to be good advice.

Thanks much!

-Jared

Well, this is not easy to explain to a 5 year old… LOL… But, let’s try it…

First, you have to create your database with tables and fields that match your user’s list.
This is the most important as everything will run from it. The simplest way to do this is to
use your host’s system to create and set up your tables and fields. All hosting companies
have something set up for you to use for this.

To set up tables, think of the major groups of info you need. A table for your users, let’s call it
“Users”. (Note caps are important! If you use them, you must use them in your code!) And,
perhaps a table for other important data such as leagues, teams, payments, etc…

Once you have your “Users” table created, create the needing fields for it. This would include all
of the normal data such as Name, Address, PhoneNumber, EmailAddress, Age, Sex, Birthdate (for
sending out Happy-Birthday-Messages), DateBecameMember, LastDateTheyWon… ANY ANY ANY
Anything that you might want. Remember, you can add Fields later on. But, it helps to gather all
of your data now and think ahead as it will make it easier later on. Most of the data is already done
for you, in your email forms.

Next comes some general programming. When the data is posted and the emails are sent as you
mentioned, add code to also place this data into the database. First, make sure you have some sort
of “FLAG” in the Users table for keeping tract of the status of the new member. I use “UserStatus”.
I put “New” in it if a new member is applying for membership, “Member” once they are validated and
paid dues or whatever, “Admin” if they are an administrator. You can use any other type of list for
you use that fits your project. The Admin will later have options to change these, such as if someone
does not pay their dues, they can be moved from “Member” to “Pending” or something. Anyway,
once the email is sent and the database is updated, the member info is useable by your code. This
can be pulled and listed in a table format so that the owner can review it and make changes, etc.

There are several steps to learn to access the database. The easiest way is to use queries. The steps are fairly simple.

  1. make a connection to your database
  2. create a query to be executed
  3. execute the query
  4. get the results of the query for display or updating
  5. close the connection to the database
    All of these steps sound complicated, but, are very easy to do. I suggest you use a PHP documentation site or learning site for these. Here are the two that I suggest:
    http://www.w3schools.com/php/php_mysql_intro.asp (General learning)
    http://php.net/manual/en/function.mysql-connect.php (For PHP code formats)
    You can find all you need there. You will have to learn how to create queries for updating, deleting and formatting displays by using searches built into the query. And, when you get stuck, you know where to ask your questions… Good luck, hope this helped…

Great reply, ErnieAlex! I have searched all over the web for something as simplistic as this. I will continue to reply to this thread with questions. Please subscribe to it, as I could certainly use your continued assistance.

Thank you very much!

Jared

PS - I see you’re in VT. I was born and raised in Nashua, NH. Good to see another NorthEasterner…

LOL, small world… I lived in Manchester, NH for 20 years… Was in Nashua a lot!

CYA in the bitstream...

So, I’ve got a small registration script (create a username, password, and reCaptcha). I have another registration script that I created at http://www.php-login-script.com. It contains things like Name, Phone#, Gender, Email, etc, etc… I’m trying to combine them.

I like the extensive features of the one I created at php-login-script.com, but I need the security created in the small registration script. I’ve posted them both here, and I’ve tried combining them, but I keep FAILING. Please help, if you can…

Small Registration Script…

[php]<?php

//require user configuration and database connection parameters
require(‘config.php’);

//pre-define validation parameters

$usernamenotempty=TRUE;
$usernamevalidate=TRUE;
$usernamenotduplicate=TRUE;
$passwordnotempty=TRUE;
$passwordmatch=TRUE;
$passwordvalidate=TRUE;
$captchavalidation= TRUE;

//Check if user submitted the desired password and username
if ((isset($_POST[“desired_password”])) && (isset($_POST[“desired_username”])) && (isset($_POST[“desired_password1”]))) {

//Username and Password has been submitted by the user
//Receive and validate the submitted information

//sanitize user inputs

function sanitize($data){
$data=trim($data);
$data=htmlspecialchars($data);
$data=mysql_real_escape_string($data);
return $data;
}

$desired_username=sanitize($_POST[“desired_username”]);
$desired_password=sanitize($_POST[“desired_password”]);
$desired_password1=sanitize($_POST[“desired_password1”]);

//validate username

if (empty($desired_username)) {
$usernamenotempty=FALSE;
} else {
$usernamenotempty=TRUE;
}

if ((!(ctype_alnum($desired_username))) || ((strlen($desired_username)) >11)) {
$usernamevalidate=FALSE;
} else {
$usernamevalidate=TRUE;
}

if (!($fetch = mysql_fetch_array( mysql_query(“SELECT username FROM authentication WHERE username=’$desired_username’”)))) {
//no records for this user in the MySQL database
$usernamenotduplicate=TRUE;
}
else {
$usernamenotduplicate=FALSE;
}

//validate password

if (empty($desired_password)) {
$passwordnotempty=FALSE;
} else {
$passwordnotempty=TRUE;
}

if ((!(ctype_alnum($desired_password))) || ((strlen($desired_password)) < 8)) {
$passwordvalidate=FALSE;
} else {
$passwordvalidate=TRUE;
}

if ($desired_password==$desired_password1) {
$passwordmatch=TRUE;
} else {
$passwordmatch=FALSE;
}

//Validate recaptcha
require_once(‘recaptchalib.php’);
$resp = recaptcha_check_answer ($privatekey,
$_SERVER[“REMOTE_ADDR”],
$_POST[“recaptcha_challenge_field”],
$_POST[“recaptcha_response_field”]);

if (!$resp->is_valid) {
//captcha validation fails
$captchavalidation=FALSE;
} else {
$captchavalidation=TRUE;
}

if (($usernamenotempty==TRUE)
&& ($usernamevalidate==TRUE)
&& ($usernamenotduplicate==TRUE)
&& ($passwordnotempty==TRUE)
&& ($passwordmatch==TRUE)
&& ($passwordvalidate==TRUE)
&& ($captchavalidation==TRUE)) {
//The username, password and recaptcha validation succeeds.

//Hash the password
//This is very important for security reasons because once the password has been compromised,
//The attacker cannot still get the plain text password equivalent without brute force.

function HashPassword($input)
{
//Credits: http://crackstation.net/hashing-security.html
//This is secure hashing the consist of strong hash algorithm sha 256 and using highly random salt
$salt = bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM));
$hash = hash(“sha256”, $salt . $input);
$final = $salt . $hash;
return $final;
}

$hashedpassword= HashPassword($desired_password);

//Insert username and the hashed password to MySQL database

mysql_query(“INSERT INTO authentication (username, password) VALUES (’$desired_username’, ‘$hashedpassword’)”) or die(mysql_error());
//Send notification to webmaster
$message = “Someone has just registered at JPC Solutions Sports Page: $desired_username”;
mail($email, $subject, $message, $from);
//redirect to login page
header(sprintf(“Location: %s”, $loginpage_url));
exit;
}
}
?>

Register as a Valid User .invalid { border: 1px solid #000000; background: #FF00FF; }

User registration Form


Hi! Welcome to my page. We're gladd you're here. We invite you to register your information below. Thanks!

Username: (alphanumeric less than 12 characters) " id="desired_username" name="desired_username">

Password: (alphanumeric greater than 8 characters) " id="desired_password" >

Type the password again: " id="desired_password1" >


Type the captcha below:

<?php require_once('recaptchalib.php'); echo recaptcha_get_html($publickey); ?>



Back to Homepage
<?php if ($captchavalidation==FALSE) echo 'Please enter correct captcha'; ?>
<?php if ($usernamenotempty==FALSE) echo 'You have entered an empty username.'; ?>
<?php if ($usernamevalidate==FALSE) echo 'Your username should be alphanumeric and less than 12 characters.'; ?>
<?php if ($usernamenotduplicate==FALSE) echo 'Please choose another username, your username is already used.'; ?>
<?php if ($passwordnotempty==FALSE) echo 'Your password is empty.'; ?>
<?php if ($passwordmatch==FALSE) echo 'Your password does not match.'; ?>
<?php if ($passwordvalidate==FALSE) echo 'Your password should be alphanumeric and greater 8 characters.'; ?>
<?php if ($captchavalidation==FALSE) echo 'Your captcha is invalid.'; ?>
[/php]

Here is the form script created at php-login-script.com

[php]<?php

This block must be placed at the very top of page.

--------------------------------------------------

require_once( dirname(FILE).’/form.lib.php’ );
phpfmg_display_form();

--------------------------------------------------

function phpfmg_form( $sErr = false ){
$style=" class=‘form_text’ ";

?>

Please check the required fields

  1. Basic Information
  2. First Name *
    " class='text_box'>
  3. Last Name *
    " class='text_box'>
  4. Phone Number  
    " class='text_box'>
  5. Create a Password *
    " class='text_box'>
  6. Gender *
    <?php phpfmg_dropdown( 'field_5', "Male|Female|Prefer Not to Answer" );?>
  7. Email Address  
    " class='text_box'>

  8. Additional Information
  9. Street Address *
    " class='text_box'>
  10. City *
    " class='text_box'>
  11. State *
    <?php phpfmg_dropdown( 'field_10', "Arizona|Alabama|Alaska||Arkansas|California|Colorado|Connecticut|Delaware|Florida|Georgia|Hawaii|Idaho|Illinois|Indiana|Iowa|Kansas|Kentucky|Louisiana|Maine|Maryland|Massachusetts|Michigan|Minnesota|Mississippi|Missouri|Montana|Nebraska|Nevada|New Hampshire|New Jersey|New Mexico|New York|North Carolina|North Dakota|Ohio|Oklahoma|Oregon|Pennsylvania|Rhode Island|South Carolina|South Dakota|Tennessee|Texas|Utah|Vermont|Virginia|Washington|West Virginia|Wisconsin|Wyoming" );?>
  12. Zip Code *
    " class='text_box'>
  13. Date of Birth *
    <?php $field_12 = array( 'month' => "-MM- =,|01|02|03|04|05|06|07|08|09|10|11|12", 'day' => "-DD- =,|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31", 'startYear' => date("Y")+0, 'endYear' => date("Y")-62, 'yearPrompt' => '-YYYY-', 'format' => "mm/dd/yyyy", 'separator' => "/", 'field_name' => "field_12", ); phpfmg_date_dropdown( $field_12 ); ?>
    <div id='field_12_tip' class='instruction'></div>
    </div>
    

  14. Free Agents - Select Which Leagues you are Interested in Playing for...
  15. Please select a league *
    <?php phpfmg_checkboxes( 'field_14', "Tuesday Co-Ed|Friday Co-Ed|Saturday Soccer League|Sunday Soccer League|Flag Football|Kickball|Women's Soccer" );?>

  16. Please send us your comments!  
    <?php phpfmg_hsc("field_16"); ?>
    <div id='field_16_tip' class='instruction'></div>
    </div>
    
  17. Security Code: *
    <?php phpfmg_show_captcha(); ?>
  18.         <li>
            <div class='col_label'>&nbsp;</div>
            <div class='form_submit_block col_field'>
    
                <input type='submit' value='Submit' class='form_button'>
                <span id='phpfmg_processing' style='display:none;'>
                    <img id='phpfmg_processing_gif' src='<?php echo PHPFMG_ADMIN_URL . '?mod=image&amp;func=processing' ;?>' border=0 alt='Processing...'> <label id='phpfmg_processing_dots'></label>
                </span>
            </div>
            </li>
    
    <?php phpfmg_javascript($sErr); } # end of form function phpfmg_form_css(){ ?> body{ margin-left: 18px; margin-top: 18px; } body{ font-family : Verdana, Arial, Helvetica, sans-serif; font-size : 13px; color : #474747; background-color: transparent; } select, option{ font-size:13px; } ol.phpfmg_form{ list-style-type:none; padding:0px; margin:0px; } ol.phpfmg_form li{ margin-bottom:5px; clear:both; display:block; overflow:hidden; width: 100% } .form_field, .form_required{ font-weight : bold; } .form_required{ color:red; margin-right:8px; } .field_block_over{ } .form_submit_block{ padding-top: 3px; } .text_box, .text_area, .text_select { width:300px; } .text_area{ height:80px; } .form_error_title{ font-weight: bold; color: red; } .form_error{ background-color: #F4F6E5; border: 1px dashed #ff0000; padding: 10px; margin-bottom: 10px; } .form_error_highlight{ background-color: #F4F6E5; border-bottom: 1px dashed #ff0000; } div.instruction_error{ color: red; font-weight:bold; } hr.sectionbreak{ height:1px; color: #ccc; } #one_entry_msg{ background-color: #F4F6E5; border: 1px dashed #ff0000; padding: 10px; margin-bottom: 10px; } <?php phpfmg_text_align();?> <?php } # end of css ?>[/php]

Well, I am confused what you are trying to do. First, PHP is designed to except and process Windows Forms info and to respond back with errors and messages. But, it is NOT a CLIENT-SIDE programming system. It is designed as SERVER-SIDE only. So there is no easy way to post to yourself using PHP. What you end up with after PHP is processed, is just HTML and Javascipt/Jquery… If you really want CLIENT-SIDE programming on a page, use Javascript and Jquery…

Please explain why you would want to merge your SERVER-SIDE code with your CLIENT-SIDE code?
Maybe I am missing something…

Thanks for getting back to me… I guess this is what I’m trying to do.

I uploaded this script to a PHP file, and then put it inside an iframe on the html page you see displayed.
Check out this site: http://www.azsportsleague.com/registration.html

I created this page, in a sub-domain on my site for testing purposes.
On my own website: http://sports.jpcsolutions.com/register.php

On the AZSportsLeague website, do you see the look and feel of that form? Again, it’s an HTML form, with an iframe. Contained in the iframe is a PHP form, but it’s only set up to send mail to a specific person. I want it to dump the data entered into a database, which would then create a profile page for the customer. The customer logs in and makes changes to his/her profile as needed.

But, in another sense, I also like the way sports.jpcsolutions.com acts. I do have that set up to dump the Username/Password to a database. That works fine. There’s authentication to verify the same Username isn’t created twice, etc.

Does this make any more sense than it did before? If not, let’s hash it out. You’re the only one that’s given me direction with out all the confusion so far, so I’d like to continue working with you.

Regards,

Jared

Okay, I think what you are asking is…

The first site is NOT yours and you like the way it looks.

Your site, you want to have similar info, but, to look like the first site.

Correct? Well, ANY form no matter how it looks can dump data into a database. And, ANY form or HTML page can be “pretty” using CSS or whatever to make it fancy… ANYbody can do this, including you. First, we need to know a bit of basic info…

You posted two sites. Assuming you own the second one, the first one looks like it uses a lot CSS. Do you understand how to use CSS? Next, do you have a list of actual problems I or we can solve for you?
I liked the first site you listed. It looks like a normal, nice site. The second is basically a nice form. I might be guessing that you want to know how to spoof it up to look better… If so, we can help with that, too…

Sponsor our Newsletter | Privacy Policy | Terms of Service