I'm trying to create a form that will create a user in my database, so they can have a profile page. I'd also like the form to send an email to confirm activation. Where is my form disconnecting? As of right now, I'm not logging any content in my db and no email is being sent.
<?php include ("session.php"); ?>
<?php // Set error message as blank upon arrival to page
$errorMsg = "";
// First we check to see if the form has been submitted
if (isset($_POST['username'])){
//Connect to the database through our include
include_once "connect_to_mysql.php";
// Filter the posted variables
$username = ereg_replace("[^A-Za-z0-9]", "", $_POST['username']); // filter everything but numbers and letters
$address = ereg_replace("[^A-Z a-z0-9]", "", $_POST['address']); // filter everything but spaces, numbers, and letters
$city = ereg_replace("[^A-Z a-z0-9]", "", $_POST['state']); // filter everything but spaces, numbers, and letters
$state = ereg_replace("[^A-Z a-z0-9]", "", $_POST['city']); // filter everything but spaces, numbers, and letters
$accounttype = ereg_replace("[^a-z]", "", $_POST['accounttype']); // filter everything but lowercase letters
$zip = ereg_replace("[^a-z]", "", $_POST['zip']); // filter everything but lowercase letters
$name = ereg_replace("[^A-Z a-z0-9]", "", $_POST['name']); // filter everything but spaces, numbers, and letters
$fax = ereg_replace("[^A-Z a-z0-9]", "", $_POST['fax']); // filter everything but spaces, numbers, and letters
$company = ereg_replace("[^A-Z a-z0-9]", "", $_POST['company']); // filter everything but spaces, numbers, and letters
$website = ereg_replace("[^A-Z a-z0-9]", "", $_POST['website']); // filter everything but spaces, numbers, and letters
$numemployees = ereg_replace("[^A-Z a-z0-9]", "", $_POST['numemployees']); // filter everything but spaces, numbers, and letters
$yearsbusiness = ereg_replace("[^A-Z a-z0-9]", "", $_POST['yearsbusiness']); // filter everything but spaces, numbers, and letters
$annualrevenue = ereg_replace("[^A-Z a-z0-9]", "", $_POST['annualrevenue']); // filter everything but spaces, numbers, and letters
$industrysector = ereg_replace("[^A-Z a-z0-9]", "", $_POST['industrysector']); // filter everything but spaces, numbers, and letters
$preferredcontact = ereg_replace("[^A-Z a-z0-9]", "", $_POST['preferredcontact']); // filter everything but spaces, numbers, and letters
$referralsource = ereg_replace("[^A-Z a-z0-9]", "", $_POST['referralsource']); // filter everything but spaces, numbers, and letters
$email = stripslashes($_POST['email']);
$email = strip_tags($email);
$email = mysql_real_escape_string($email);
$password = ereg_replace("[^A-Za-z0-9]", "", $_POST['password']); // filter everything but numbers and letters
// Check to see if the user filled all fields with
// the "Required"(*) symbol next to them in the join form
// and print out to them what they have forgotten to put in
if((!$username) || (!$address) || (!$state) || (!$city) || (!$accounttype) || (!$email) || (!$password)){
$errorMsg = "You did not submit the following required information!<br /><br />";
if(!$username){
$errorMsg .= "--- User Name";
} else if(!$name){
$errorMsg .= "Please Enter Your Full Name.";
} else if(!$phone){
$errorMsg .= "Please enter your Phone Number.";
} else if(!$fax){
$errorMsg .= "Please enter your Fax Number.";
} else if(!$email){
$errorMsg .= "Please enter your Email Address.";
} else if(!$address){
$errorMsg .= "Please enter your Address.";
} else if(!$city){
$errorMsg .= "Please enter the City in which you reside";
} else if(!$state){
$errorMsg .= "Please enter the State in which you reside.";
} else if(!$zip){
$errorMsg .= "Please enter the Zip Code in which you reside";
} else if(!$company){
$errorMsg .= "Please enter the name f your Company.";
} else if(!$website){
$errorMsg .= "Please enter your company website.";
} else if(!$numemployees){
$errorMsg .= "Please enter the current number of employees at your company.";
} else if(!$yearsbusiness){
$errorMsg .= "Please enter the number of years you've been in business.";
} else if(!$annualrevenue){
$errorMsg .= "Please enter your companies Approximate Annual Revenue.";
} else if(!$industrysector){
$errorMsg .= "Please enter the Industry Sector.";
} else if(!$accounttype){
$errorMsg .= "Please choose a Membership Type.";
} else if(!$preferredcontact){
$errorMsg .= "Please enter your preferred method of contact.";
} else if(!$referralsource){
$errorMsg .= "Please enter the Referral Source.";
} else
// Database duplicate Fields Check
$sql_username_check = mysql_query("SELECT id FROM members WHERE username='$username' LIMIT 1");
$sql_email_check = mysql_query("SELECT id FROM members WHERE email='$email' LIMIT 1");
$username_check = mysql_num_rows($sql_username_check);
$email_check = mysql_num_rows($sql_email_check);
if ($username_check > 0){
$errorMsg = "<u>ERROR:</u><br />Your User Name is already in use inside our system. Please try another.";
} else if ($email_check > 0){
$errorMsg = "<u>ERROR:</u><br />Your Email address is already in use inside our system. Please try another.";
} else {
// Add MD5 Hash to the password variable
$hashedPass = md5($password);
// Add user info into the database table, claim your fields then values
$sql = mysql_query("INSERT INTO members (username, email, password, phone, address, city, state, zip, emailactivated, accounttype, lastlogin, signupdate, name, fax, company, website, numemployees, yearsbusiness, annualrevenue, industrysector, preferredcontact, referralsource)
VALUES('$username', '$email', '$password', '$phone', '$address', '$city', '$state', '$zip', '$emailactivated', '$accounttype', '$lastlogin', '$signupdate', '$name', '$fax', '$company', '$website', '$numemployees', '$yearsbusiness', '$annualrevenue', '$industrysector', '$preferredcontact', '$referralsource', now())") or die (mysql_error());
// Get the inserted ID here to use in the activation email
$id = mysql_insert_id();
// Create directory(folder) to hold each user files(pics, MP3s, etc.)
mkdir("memberFiles/$id", 0755);
// Start assembly of Email Member the activation link
$to = "$email";
// Change this to your site admin email
$from = "###############";
$subject = "One Last Step";
//Begin HTML Email Message where you need to change the activation URL inside
$message = '<html>
<body bgcolor="#FFFFFF">
Hi ' . $name . ',
<br /><br />
One Last Step before we can review your application.
<br /><br />
Please click here to activate now >>
<a href="http://www.############.com/activation.php?id=' . $id . '">
ACTIVATE NOW</a>
<br /><br />
Your Login Data is as follows:
<br /><br />
E-mail Address: ' . $email . ' <br />
Password: ' . $password . '
<br /><br />
Thanks!
<br /><br />
Houstonians For A Better Tomorrow
</body>
</html>';
// end of message
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
$to = "$to";
// Finally send the activation email to the member
mail($to, $subject, $message, $headers);
// Then print a message to the browser for the joiner
print "<br /><br /><br /><h4>OK $firstname, one last step to verify your email identity:</h4><br />
We just sent an Activation link to: $email<br /><br />
<strong><font color=\"#990000\">Please check your email inbox in a moment</font></strong> to click on the Activation <br />
Link inside the message. After email activation you can log in.";
exit(); // Exit so the form and page does not display, just this success message
} // Close else after database duplicate field value checks
} // Close else after missing vars check
} //Close if $_POST
?>
<?php include ("header.php"); ?>
</div>
</div>
<?php include ("subhead.php"); ?>
<!-- Content Wrapper -->
<div class="contentWrapper">
<div class="outerShadow">
</div>
<div class="innerShadow">
</div>
<div class="center clearfix">
<!-- Additional clearfix necessary for non floated objects -->
<div class="clearfix">
</div>
<!-- Content Starts - Header template should end here -->
<!--Left layout column -->
<div class="siteColumnLeft">
<div class="column">
<table width="750" align="center" cellpadding="4">
<tr>
<td width="7%">Please complete the entire application. </td>
</tr>
</table>
<table width="600" align="center" cellpadding="5">
<form action="join_form.php" method="post" enctype="multipart/form-data">
<tr>
<td colspan="2"><font color="#FF0000"><?php echo "$errorMsg"; ?></font></td>
</tr>
<tr>
<td width="300"><div align="right">User Name:</div></td>
<td width="450"><input name="username" type="text" value="<?php echo "$username"; ?>" /></td>
</tr>
<tr>
<td width="300"><div align="right"> Password: </div></td>
<td width="450"><input name="password" type="password" value="<?php echo "$password"; ?>" />
<font size="-2" color="#006600">(letters or numbers only, no spaces no symbols)</font></td>
</tr>
<tr>
<td width="300"><div align="right">Name:</div></td>
<td width="450"><input name="name" type="text" value="<?php echo "$name"; ?>" /></td>
</tr>
<tr>
<td width="300"><div align="right">Phone:</div></td>
<td width="450"><input name="phone" type="text" value="<?php echo "$phone"; ?>" /></td>
</tr>
<tr>
<td width="300"><div align="right">Fax:</div></td>
<td width="450"><input name="fax" type="text" value="<?php echo "$fax"; ?>" /></td>
</tr>
<tr>
<td width="163"><div align="right">Email:</div></td>
<td width="450"><input name="email" type="text" value="<?php echo "$email"; ?>" /></td>
</tr>
<tr>
<td width="300"><div align="right">Address:</div></td>
<td width="450"><input name="address" type="text" value="<?php echo "$address"; ?>" /></td>
</tr>
<tr>
<td width="300"><div align="right">City: </div></td>
<td width="450"><input name="city" type="text" value="<?php echo "$city"; ?>" /></td>
</tr>
<tr>
<td width="300"><div align="right">State: </div></td>
<td width="450"><input name="state" type="text" value="<?php echo "$state"; ?>" /></td>
</tr>
<tr>
<td width="300"><div align="right">Zip Code: </div></td>
<td width="450"><input name="zip" type="text" value="<?php echo "$zip"; ?>" /></td>
</tr>
<tr>
<td width="300"><div align="right">Company: </div></td>
<td width="450"><input name="company" type="text" value="<?php echo "$company"; ?>" /></td>
</tr>
<tr>
<td width="300"><div align="right">Website: </div></td>
<td width="450"><input name="website" type="text" value="<?php echo "$website"; ?>" /></td>
</tr>
<tr>
<td width="300"><div align="right">No. Of Employees: </div></td>
<td width="450"><input name="numemployees" type="text" value="<?php echo "$numemployees"; ?>" /></td>
</tr>
<tr>
<td width="300"><div align="right">How many years have you been in business? </div></td>
<td width="450"><input name="yearsbusiness" type="text" value="<?php echo "$yearsbusiness"; ?>" /></td>
</tr>
<tr>
<td width="300"><div align="right">What are your Approximate Annual Revenues? </div></td>
<td width="450"><input name="annualrevenue" type="text" value="<?php echo "$annualrevenue"; ?>" /></td>
</tr>
<tr>
<td width="300"><div align="right">Industry Sector: </div></td>
<td width="450"><input name="industrysector" type="text" value="<?php echo "$industrysector"; ?>" /></td>
</tr>
<tr>
<td width="300"><div align="right">What level would you like to become a member of Houstonians For A Better Tomorrow? </div></td>
<td width="450"><select name="accounttype">
<option value="<?php echo "$accounttype"; ?>"><?php echo "$accounttype"; ?></option>
<option value="a">Urban Small Business Member</option>
<option value="b">Corporate Member</option>
<option value="c">Non-Profit</option>
</select></td>
</tr>
<tr>
<td width="300"><div align="right">How do you prefer to receive updates? </div></td>
<td width="450"><select name="preferredcontact">
<option value="<?php echo "$preferredcontact"; ?>"><?php echo "$preferredcontact"; ?></option>
<option value="a">Email</option>
<option value="b">Fax</option>
<option value="c">Direct Mail</option>
</select></td>
</tr>
<tr>
<td width="300"><div align="right">How did you find out about Houstonians For A Better Tomorrow?</div></td>
<td width="450"><select name="referralsource">
<option value="<?php echo "$referralsource"; ?>"><?php echo "$referralsource"; ?></option>
<option value="a">Advertising - TV </option>
<option value="b">Advertising - Radio</option>
<option value="c">Advertising - Online</option>
<option value="c">Advertising - Print</option>
<option value="c">Referral</option>
</select></td>
</tr>
<tr>
<td width="300"><div align="right"></div></td>
<td width="450"><input type="submit" name="Submit" value="Submit Form" /></td>
</tr>
</form>
</table>
</div></div>
</div>
</div>
<!-- Twitter Widget -->
<div class="twitterWidget">
<div class="center">
<!-- Simply change the href to your username -->
<a class="profileLink" href="http://twitter.com/##############"></a><p>Loading<span>Retrieving latest tweet...</span></p>
</div>
</div>
<?php include ("footer.php"); ?>
</body></html>
Presuming join_form.php is the current form (use $_SERVER['PHP_SELF'] instead)... Insert some debugging code so you can follow what is happening: at the top of the document put the following so you can see what is being passes.
After each `if' statement echo "Here 1" or "Here 2" so you can see where the code is going.
After your ereg_replace() use:
Then you can start to debug your problem.