script needed for html page on linux server: visitor form, and to display data gathered

I think I need 2 scripts:
1.) a data collection form script
2.) data display script

I need a visitor form to allow site visitors to voice their agreement with the site, and for the site to display the information back on the site. I would like to collect: name, city, state/region, country, and ip address

and then display

name, city, state/region, country in a scrolling display or some sort of display that automatically updates. If country=USA, then they are a member, if not, they are a supporter.

I know that plug-ins and extensions are available for Wordpress that do these kind of things, but this is for a plain old ordinary HTML site.

mySQL, CGI, Perl assets are all available on the hosting server.

Help! I need something really quick! Do you know about any scripts that can do this?

After the visitor data is collected, the data would be saved (mySQL database?) and also displayed on the website, maybe something like this:
A mock-up of what the data display might look like. Collected data, and statistics.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jason C. LevineDon't talk to me.Commented:
Do you have any scripting knowledge or are you asking us to give you a complete, ready-to-go solution?
dtleahyAuthor Commented:
Hi Jason,

I am a programmer, but I am a dinosaur programmer. By that, I mean that I may be able to take a "canned" script that is close to the solution and modify it. Because this site is hosted on a Linux server, I can't use my dinosaur ASP coding experience for this.

Seems like the forms scrips that I have used in the past just sent an email with data, but I suspect there are forms scripts that will insert records in a database instead.

Actually, the more I think about this, I'm wondering if this functionality is just too hard to do on a Linux server using .html files for pages.

Jason C. LevineDon't talk to me.Commented:
>> Actually, the more I think about this, I'm wondering if this functionality is just too hard to
>> do on a Linux server using .html files for pages.

No, it's quite easy but there are some things that are easier than others.

You'll need PHP or Perl (PHP preferred) if you want to do this on relatively easily on *nix.  Do you have PHP in the environment?
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

dtleahyAuthor Commented:
Sorry for being slow to answer. Yes, the server environment has php 5 "latest version" and the mySQL is also v5. Perl is available, as are Ruby, Python... it is a big hosting company that has the servers ready for most people's needs.

By the way, I couldn't really sit down and write web pages in php from scratch, but have modified code by others. I wonder if the html to php page code converters actually work. I suppose they do at least somewhat, with some surprises. I know html and php can be both be used (mixed) on pages, but I'm not sure if converting the entire page to php would have advantages.

Jason C. LevineDon't talk to me.Commented:
You don't need to convert a page to PHP and the converters you mention are worthless anyway.

What your app will look like is this:

1.  HTML page with a form to collect the data.  The form will have its action parameter pointing to a php file.

2.  The PHP file will take the form input an store it in a MySQL table.  Once that's done, it will redirect to a new php page

3. The new PHP page will query the table and spit out the desired results in a loop for display.

You can mix php scripts inline with HTML.  If the page is named .php then your server will parse the php code before sending the output to the browser:

<p>This is a mix of HTML and <?php echo "PHP"; ?> on the same line.</p>

Give me a little time to find a suitable basic script for step 2 to get you started.
dtleahyAuthor Commented:
Awesome! Thanks for your help, Jason.

Here is the beginnings of the input form:

I need to add a hidden field capturing the ip address, I'll probably also add a spam-bot deterrent like a challenge question.

I'll need to figure out how to send the input data to a database, have the form send out a confirmation email, and when they confirm, then update a field in the database showing that they are validated, and the current time/date stamp.
Back on the web main page, the other script will be running, showing a tally of totals and a small scrolling window with the latest validated individuals.

Jason C. LevineDon't talk to me.Commented:
>> I need to add a hidden field capturing the ip address

No. With PHP the user's IP is available as a system variable: $ip=$_SERVER['REMOTE_ADDR'];

>>  I'll probably also add a spam-bot deterrent like a challenge question.

I recommend reCaptcha.

For the PHP file, I recommend you start with this simple tutorial:

Here's how to get the number of people who submit a form:


mysql_connect("localhost","root","admin"); //database connection, change to match 

// Query the database and get the count

  $result = mysql_query("SELECT * FROM tablename");
  $num_rows = mysql_num_rows($result);

// Display the results

  echo $num_rows;

Open in new window

And here is a pretty good intro to retrieving records and displaying them:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dtleahyAuthor Commented:
<input type="hidden" name="ipaddy" value="$ip=$_SERVER['REMOTE_ADDR'];" />

Open in new window

However, I read somewhere NOT to simply get the ip address in a form as a hidden variable and and send it to a processing page, because that can be hacked. They suggested sending the ipaddress as a variable instead... but failed to say how to do that.

Jason C. LevineDon't talk to me.Commented:
The code snippet above should be:

<input type="hidden" name="ipaddy" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" />

"They suggested sending the ipaddress as a variable instead... but failed to say how to do that. "

You're going to need to learn how to manipulate PHP to do it without the form.  Basically, when processing the form variables into the SQL statement, you add the $_SERVER['REMOTE_ADDR']; to the mix at that time.
Ray PaseurCommented:
You do not need to send the IP address in a form.  The client browser will set it in the request.  It will be found in $_SERVER["REMOTE_ADDR"].  And while it is technically possible to make a phony request with a bogus IP address, it is more nuisance than it is worth, especially if you have a CAPTCHA test on the page.

Agree with most everything jason1178 has said, but I am not a fan of reCaptcha.  The principles of Captcha make good sense, but their images cause eyestrain.  This article talks a little bit about how it works, and shows a way to make images that are easier to read.
dtleahyAuthor Commented:
Thanks Jason and Ray,

I've got the database built, and am working on the php processing page to insert a record and send a confirmation email...

Jason C. LevineDon't talk to me.Commented:
"I am not a fan of reCaptcha.  The principles of Captcha make good sense, but their images cause eyestrain."

It's still better than whatever the hell Google does with their captchas :)  I can never get those things right.

Helluva nice article, Ray.
dtleahyAuthor Commented:
Do you think a simple "challenge question" inadequate? I know people set up bots to find forum software, and auto-register, and when I added a simple challenge question, it completely stopped the bots. I do hate CAPTCHA as well, and often find myself refreshing several times before I find one I can kinda sorta read.

If we're talking about humans, and you're trying to stop a malevolent human from repeatedly inputting phony data (like silly names, just to discredit the data set), I think that is a different and harder issue to deal with. If they use something that masks their IP address, and they input different phony data each time, I don't know how you could stop them.

That is a cool article, Ray.
Ray PaseurCommented:
a simple "challenge question"
I think this is almost always adequate.  Any CAPTCHA test at all is usually a sufficient deterrent.  If you have a bad actor who happens to be human and you can identify them, you can delete their posts.  This is the "report abuse" strategy.  If the same post is flagged more than once or twice, you can let it rise to the level of moderator attention.  It's usually pointless to try to write "dirty words filters" because you're never going to be able to outsmart all every smartass who will post things from (for example) that semi-famous Arab named "Azheet Mehdrawers."  Or "Woody Johnson" (who might be legit; some parents have a sense of humor).

Just be carefully thoughtful about associating a bad actor too closely with an IP address.  Some ISPs reuse IP addresses and postings from a corporate intranet may have several individual computers behind the same IP address.
dtleahyAuthor Commented:
Jumping around a bit, but I am stuck with a lack of understanding of the connection string to the mySQL database, or else have some other error...



@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO `therealdatabase`.`thetablename` (`rbname`, `rbcity`, `rbstate`, `rbcountry`, `rbemail`, `rbip`,  `rbokemail`) VALUES ('$rbname', '$rbcity', '$rbstate', '$rbcountry', '$rbemail', '$rbip', '$rbokemail')";



Open in new window

results in:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'myrealusername'@'localhost' (using password: YES) in /home/resetbutton/public_html/stepone.php on line 15
Unable to select database

Open in new window


I am reluctant to post the real database name, table name, password on a public forum, so to post it here at EE I substituted phony text. The real file has the real strings, and I have triple checked them.

The database really is located on the (shared, commercial, hosting) server in my "localhost" folder.
Ray PaseurCommented:
Try a design pattern more like this one.  It will let you connect and select your data base.  It will tell you at least a little something about why you have a problem using your data base.
<?php // RAY_mysql_example.php


$db_host = "localhost"; // PROBABLY THIS IS OK
$db_name = "??";        // GET THESE FROM YOUR HOSTING COMPANY
$db_user = "??";
$db_word = "??";

if (!$db_connection = mysql_connect("$db_host", "$db_user", "$db_word"))
    $errmsg = mysql_errno() . ' ' . mysql_error();
    echo "<br/>NO DB CONNECTION: ";
    echo "<br/> $errmsg <br/>";

if (!$db_sel = mysql_select_db($db_name, $db_connection))
    $errmsg = mysql_errno() . ' ' . mysql_error();
    echo "<br/>NO DB SELECTION: ";
    echo "<br/> $errmsg <br/>";
    die('NO DATA BASE');

Open in new window

dtleahyAuthor Commented:
Thanks Ray. I did find the problem in the previous code and fixed it.

The username was truncated (the hosting company automatically provides the database_
dtleahyAuthor Commented:
Here is a resource I just found for my next steps...

(Email activation for php forms)

dtleahyAuthor Commented:
I had the form working. Added a record to the database. Then, I tried to add all the activation code, and now, not working. No error on submit, it reloads the same page and clears the textboxes (does not appear to be loading the processing/script page.

Here's my code, first for the form page, then for the processing page. Hopefully, something easy to spot will stick out.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Sign The Reset Button</title>
<script type="text/javascript" src="/js/view.js"></script>

<link href="/CSS/rb2012formview.css" rel="stylesheet" type="text/css" />
<body id="main_body" >
	<img id="top" src="Images/rb2012formtop.png" alt="" />
	<div id="form_container">
	<h1><a>Sign The Reset Button</a></h1>
		<form id="rb2012form" class="appnitro"  method="post" action="regactivate.php">
					<div class="form_description">
			<h2>Sign The Reset Button</h2>
			<p>I want fair, honest elections in the United States!</p>
			<p>I want US elections controlled by US citizens, not by Big Money from corporations, banks, special interests, and the rich!</p>
		</div>	(all fields are required)					
			<ul >
					<li id="li_1" >
		<label class="description" for="v_name">Name </label>
			<input id="v_name" name="v_name" class="element text medium" type="text" maxlength="255" value=""/> 
		</div><p class="guidelines" id="guide_1"><small>Please enter your full name, not a screen name. We are standing up publicly and demanding fair elections.</small></p> 
		</li>		<li id="li_2" >
		<label class="description" for="v_city">City </label>
			<input id="v_city" name="v_city" class="element text medium" type="text" maxlength="255" value=""/> 
		</div><p class="guidelines" id="guide_2"><small>Please enter your city</small></p> 
		</li>		<li id="li_3" >
		<label class="description" for="v_state">State or Region </label>
			<input id="v_state" name="v_state" class="element text medium" type="text" maxlength="255" value=""/> 
		</div><p class="guidelines" id="guide_3"><small>Please enter your State or Region</small></p> 
		</li>		<li id="li_5" >
		<label class="description" for="v_country">Country </label>
		<select class="element select large" id="v_country" name="v_country"> 
			<option value="" selected="selected"></option>
<option value="Afganistan">Afghanistan</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
<option value="American Samoa">American Samoa</option>
<option value="Andorra">Andorra</option>
<option value="Angola">Angola</option>
<option value="Anguilla">Anguilla</option>
<option value="Antigua &amp; Barbuda">Antigua &amp; Barbuda</option>
<option value="Argentina">Argentina</option>
<option value="Armenia">Armenia</option>
<option value="Aruba">Aruba</option>
<option value="Australia">Australia</option>
<option value="Austria">Austria</option>
<option value="Azerbaijan">Azerbaijan</option>
<option value="Bahamas">Bahamas</option>
<option value="Bahrain">Bahrain</option>
<option value="Bangladesh">Bangladesh</option>
<option value="Barbados">Barbados</option>
<option value="Belarus">Belarus</option>
<option value="Belgium">Belgium</option>
<option value="Belize">Belize</option>
<option value="Benin">Benin</option>
<option value="Bermuda">Bermuda</option>
<option value="Bhutan">Bhutan</option>
<option value="Bolivia">Bolivia</option>
<option value="Bonaire">Bonaire</option>
<option value="Bosnia &amp; Herzegovina">Bosnia &amp; Herzegovina</option>
<option value="Botswana">Botswana</option>
<option value="Brazil">Brazil</option>
<option value="British Indian Ocean Ter">British Indian Ocean Ter</option>
<option value="Brunei">Brunei</option>
<option value="Bulgaria">Bulgaria</option>
<option value="Burkina Faso">Burkina Faso</option>
<option value="Burundi">Burundi</option>
<option value="Cambodia">Cambodia</option>
<option value="Cameroon">Cameroon</option>
<option value="Canada">Canada</option>
<option value="Canary Islands">Canary Islands</option>
<option value="Cape Verde">Cape Verde</option>
<option value="Cayman Islands">Cayman Islands</option>
<option value="Central African Republic">Central African Republic</option>
<option value="Chad">Chad</option>
<option value="Channel Islands">Channel Islands</option>
<option value="Chile">Chile</option>
<option value="China">China</option>
<option value="Christmas Island">Christmas Island</option>
<option value="Cocos Island">Cocos Island</option>
<option value="Colombia">Colombia</option>
<option value="Comoros">Comoros</option>
<option value="Congo">Congo</option>
<option value="Cook Islands">Cook Islands</option>
<option value="Costa Rica">Costa Rica</option>
<option value="Cote DIvoire">Cote D'Ivoire</option>
<option value="Croatia">Croatia</option>
<option value="Cuba">Cuba</option>
<option value="Curaco">Curacao</option>
<option value="Cyprus">Cyprus</option>
<option value="Czech Republic">Czech Republic</option>
<option value="Denmark">Denmark</option>
<option value="Djibouti">Djibouti</option>
<option value="Dominica">Dominica</option>
<option value="Dominican Republic">Dominican Republic</option>
<option value="East Timor">East Timor</option>
<option value="Ecuador">Ecuador</option>
<option value="Egypt">Egypt</option>
<option value="El Salvador">El Salvador</option>
<option value="Equatorial Guinea">Equatorial Guinea</option>
<option value="Eritrea">Eritrea</option>
<option value="Estonia">Estonia</option>
<option value="Ethiopia">Ethiopia</option>
<option value="Falkland Islands">Falkland Islands</option>
<option value="Faroe Islands">Faroe Islands</option>
<option value="Fiji">Fiji</option>
<option value="Finland">Finland</option>
<option value="France">France</option>
<option value="French Guiana">French Guiana</option>
<option value="French Polynesia">French Polynesia</option>
<option value="French Southern Ter">French Southern Ter</option>
<option value="Gabon">Gabon</option>
<option value="Gambia">Gambia</option>
<option value="Georgia">Georgia</option>
<option value="Germany">Germany</option>
<option value="Ghana">Ghana</option>
<option value="Gibraltar">Gibraltar</option>
<option value="Great Britain">Great Britain</option>
<option value="Greece">Greece</option>
<option value="Greenland">Greenland</option>
<option value="Grenada">Grenada</option>
<option value="Guadeloupe">Guadeloupe</option>
<option value="Guam">Guam</option>
<option value="Guatemala">Guatemala</option>
<option value="Guinea">Guinea</option>
<option value="Guyana">Guyana</option>
<option value="Haiti">Haiti</option>
<option value="Hawaii">Hawaii</option>
<option value="Honduras">Honduras</option>
<option value="Hong Kong">Hong Kong</option>
<option value="Hungary">Hungary</option>
<option value="Iceland">Iceland</option>
<option value="India">India</option>
<option value="Indonesia">Indonesia</option>
<option value="Iran">Iran</option>
<option value="Iraq">Iraq</option>
<option value="Ireland">Ireland</option>
<option value="Isle of Man">Isle of Man</option>
<option value="Israel">Israel</option>
<option value="Italy">Italy</option>
<option value="Jamaica">Jamaica</option>
<option value="Japan">Japan</option>
<option value="Jordan">Jordan</option>
<option value="Kazakhstan">Kazakhstan</option>
<option value="Kenya">Kenya</option>
<option value="Kiribati">Kiribati</option>
<option value="Korea North">Korea North</option>
<option value="Korea Sout">Korea South</option>
<option value="Kuwait">Kuwait</option>
<option value="Kyrgyzstan">Kyrgyzstan</option>
<option value="Laos">Laos</option>
<option value="Latvia">Latvia</option>
<option value="Lebanon">Lebanon</option>
<option value="Lesotho">Lesotho</option>
<option value="Liberia">Liberia</option>
<option value="Libya">Libya</option>
<option value="Liechtenstein">Liechtenstein</option>
<option value="Lithuania">Lithuania</option>
<option value="Luxembourg">Luxembourg</option>
<option value="Macau">Macau</option>
<option value="Macedonia">Macedonia</option>
<option value="Madagascar">Madagascar</option>
<option value="Malaysia">Malaysia</option>
<option value="Malawi">Malawi</option>
<option value="Maldives">Maldives</option>
<option value="Mali">Mali</option>
<option value="Malta">Malta</option>
<option value="Marshall Islands">Marshall Islands</option>
<option value="Martinique">Martinique</option>
<option value="Mauritania">Mauritania</option>
<option value="Mauritius">Mauritius</option>
<option value="Mayotte">Mayotte</option>
<option value="Mexico">Mexico</option>
<option value="Midway Islands">Midway Islands</option>
<option value="Moldova">Moldova</option>
<option value="Monaco">Monaco</option>
<option value="Mongolia">Mongolia</option>
<option value="Montserrat">Montserrat</option>
<option value="Morocco">Morocco</option>
<option value="Mozambique">Mozambique</option>
<option value="Myanmar">Myanmar</option>
<option value="Nambia">Nambia</option>
<option value="Nauru">Nauru</option>
<option value="Nepal">Nepal</option>
<option value="Netherland Antilles">Netherland Antilles</option>
<option value="Netherlands">Netherlands (Holland, Europe)</option>
<option value="Nevis">Nevis</option>
<option value="New Caledonia">New Caledonia</option>
<option value="New Zealand">New Zealand</option>
<option value="Nicaragua">Nicaragua</option>
<option value="Niger">Niger</option>
<option value="Nigeria">Nigeria</option>
<option value="Niue">Niue</option>
<option value="Norfolk Island">Norfolk Island</option>
<option value="Norway">Norway</option>
<option value="Oman">Oman</option>
<option value="Pakistan">Pakistan</option>
<option value="Palau Island">Palau Island</option>
<option value="Palestine">Palestine</option>
<option value="Panama">Panama</option>
<option value="Papua New Guinea">Papua New Guinea</option>
<option value="Paraguay">Paraguay</option>
<option value="Peru">Peru</option>
<option value="Phillipines">Philippines</option>
<option value="Pitcairn Island">Pitcairn Island</option>
<option value="Poland">Poland</option>
<option value="Portugal">Portugal</option>
<option value="Puerto Rico">Puerto Rico</option>
<option value="Qatar">Qatar</option>
<option value="Republic of Montenegro">Republic of Montenegro</option>
<option value="Republic of Serbia">Republic of Serbia</option>
<option value="Reunion">Reunion</option>
<option value="Romania">Romania</option>
<option value="Russia">Russia</option>
<option value="Rwanda">Rwanda</option>
<option value="St Barthelemy">St Barthelemy</option>
<option value="St Eustatius">St Eustatius</option>
<option value="St Helena">St Helena</option>
<option value="St Kitts-Nevis">St Kitts-Nevis</option>
<option value="St Lucia">St Lucia</option>
<option value="St Maarten">St Maarten</option>
<option value="St Pierre &amp; Miquelon">St Pierre &amp; Miquelon</option>
<option value="St Vincent &amp; Grenadines">St Vincent &amp; Grenadines</option>
<option value="Saipan">Saipan</option>
<option value="Samoa">Samoa</option>
<option value="Samoa American">Samoa American</option>
<option value="San Marino">San Marino</option>
<option value="Sao Tome & Principe">Sao Tome &amp; Principe</option>
<option value="Saudi Arabia">Saudi Arabia</option>
<option value="Senegal">Senegal</option>
<option value="Seychelles">Seychelles</option>
<option value="Sierra Leone">Sierra Leone</option>
<option value="Singapore">Singapore</option>
<option value="Slovakia">Slovakia</option>
<option value="Slovenia">Slovenia</option>
<option value="Solomon Islands">Solomon Islands</option>
<option value="Somalia">Somalia</option>
<option value="South Africa">South Africa</option>
<option value="Spain">Spain</option>
<option value="Sri Lanka">Sri Lanka</option>
<option value="Sudan">Sudan</option>
<option value="Suriname">Suriname</option>
<option value="Swaziland">Swaziland</option>
<option value="Sweden">Sweden</option>
<option value="Switzerland">Switzerland</option>
<option value="Syria">Syria</option>
<option value="Tahiti">Tahiti</option>
<option value="Taiwan">Taiwan</option>
<option value="Tajikistan">Tajikistan</option>
<option value="Tanzania">Tanzania</option>
<option value="Thailand">Thailand</option>
<option value="Togo">Togo</option>
<option value="Tokelau">Tokelau</option>
<option value="Tonga">Tonga</option>
<option value="Trinidad &amp; Tobago">Trinidad &amp; Tobago</option>
<option value="Tunisia">Tunisia</option>
<option value="Turkey">Turkey</option>
<option value="Turkmenistan">Turkmenistan</option>
<option value="Turks &amp; Caicos Is">Turks &amp; Caicos Is</option>
<option value="Tuvalu">Tuvalu</option>
<option value="Uganda">Uganda</option>
<option value="Ukraine">Ukraine</option>
<option value="United Arab Erimates">United Arab Emirates</option>
<option value="United Kingdom">United Kingdom</option>
<option value="United States of America">United States of America</option>
<option value="Uraguay">Uruguay</option>
<option value="Uzbekistan">Uzbekistan</option>
<option value="Vanuatu">Vanuatu</option>
<option value="Vatican City State">Vatican City State</option>
<option value="Venezuela">Venezuela</option>
<option value="Vietnam">Vietnam</option>
<option value="Virgin Islands (Brit)">Virgin Islands (Brit)</option>
<option value="Virgin Islands (USA)">Virgin Islands (USA)</option>
<option value="Wake Island">Wake Island</option>
<option value="Wallis &amp; Futana Is">Wallis &amp; Futana Is</option>
<option value="Yemen">Yemen</option>
<option value="Zaire">Zaire</option>
<option value="Zambia">Zambia</option>
<option value="Zimbabwe">Zimbabwe</option>

		</div><p class="guidelines" id="guide_5"><small>Please select your country. Non-US citizens will be considered as &quot;supporters&quot;; US citizens will be considered as &quot;signers.&quot;</small></p> 
		</li>		<li id="li_4" >
		<label class="description" for="v_email">Email </label>
			<input id="v_email" name="v_email" class="element text large" type="text" maxlength="255" value=""/> 
		</div><p class="guidelines" id="guide_4"><small>Enter your email address. You will not be 'spammed', your address will not be shared or sold. This is only for The Reset Button.</small></p> 
		</li>		<li id="li_6" >
		<label class="description" for="v_chkok">Email address use </label>
			<input id="v_chkok" name="v_chkok" class="element checkbox" type="checkbox"  checked="checked" value="1" />
<label class="choice" for="v_chkok">Besides ONE confirmation email, is it OK to send you further emails? (There may be none, or there may be a few, but nothing overwhelming.)</label>

		</span><p class="guidelines" id="guide_6"><small>Un-check this box if you want no more than one confirmation email message.</small></p> 
					<li class="buttons">
				 <input type="hidden" name="form_id" value="rb2012form" />
				 <input type="hidden" id="ipaddy" name="ipaddy" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" />
				 <input type="hidden" name="form_submitted" value="1"/> 
				<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
		<div id="footer">
			might want to add a footer message
	<img id="bottom" src="Images/rb2012formbottom.png" alt="" />

Open in new window

and the processing page:


echo "name= " $xname

echo "email= " $xuseremail

echo "email ok= " $xokemail

echo "registering = " $_POST['form_submitted']

@mysql_select_db($database) or die( "Unable to select database");

if ($_POST['form_submitted'] == '1') {

## Form was submitted,the user is registering!

$activationcode =  mt_rand() . mt_rand() . mt_rand() . mt_rand() . mt_rand();

$query = "INSERT INTO mydatabase.xmytable (xname, xcity, xstate, xcountry, xuseremail, xuserid, xokemail, activationcode) VALUES ('$xname', '$xcity', '$xstate', '$xcountry', '$xuseremail', '$xuserid', '$xokemail','$activationcode')";

if (!mysql_query($sql))


  die('Error: ' . mysql_error());

  echo "An email has been sent to $_POST[v_email] with an activation key. Please check your mail to complete authentication, and sign The Reset Button document.";

##Send activation Email

$to      = $_POST[v_email];

$subject = " Authentication (and Signing)";

$message = "Thank you for standing up, $_POST[v_name]!\r\rYou, or someone using your email address, has completed registration at You can authenticate this registration and sign The Reset Button document by clicking the following link:\r$activationcode\r\rIf this is an error, you can ignore this email.\r\rThank You!,\ Dennis T. Leahy, (webmaster)";

$headers = 'From:' . "\r\n" .

    'Reply-To:' . "\r\n" .

    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
} else {

##User isn't registering, check verify code and change activation code to null, rbvalid to 1 on success

$queryString = $_SERVER['QUERY_STRING'];

$query = "SELECT * FROM mydatabase"; 

$result = mysql_query($query) or die(mysql_error());

  while($row = mysql_fetch_array($result)){

    if ($queryString == $row["activationcode"]){

       echo "Congratulations!" . $row["xname"] . " has signed The Reset Button document.";

       $sql="UPDATE mydatabase SET activationcode = '', rbvalid=1 WHERE (userid = $row[userid])";

       if (!mysql_query($sql))


        die('Error: ' . mysql_error());






Open in new window

dtleahyAuthor Commented:
I pared down the php to the bare minimum to send email, even hardcoded the variables, and still did not get the email to go through (to my Hotmail email account.)

I have been testing using a Hotmail account, and no mail shows up, not even as junk.

I finally tried a different email address that does not use the Hotmail/Live mailservers, and got a message in my hosting company's log file that it was "greylisted, try again in 300 seconds." That seemed odd.  

A tech from the hosting company pushed it through, and I did, finally, get the minimalist message.

So, it appears the (pared down) php code is correct, and Hotmail won't accept the email at all, and my other account (not Hotmail) was wary. The hosting company I'm using is and now I'm wondering if I am always going to have trouble sending email from there.

Jason C. LevineDon't talk to me.Commented:
Whenever you generate an email from a script it raises the spam profile considerably.  Machine-generated messages can get dumped outright by many, many receiving servers depending on how reputable your ISP is.  Check some of the open relay blacklists and spam blacklists to see if your ISP has been reported for bad behavior by some of their users.  If so, time to find a new ISP.
dtleahyAuthor Commented:
I found my error in the php 'processing code' above. (I used $query to create the query, then was using $sql to try to run it.) I fixed that, and it now works.

Activation works too.

I have clean-up to do, need to validate form fields, add challenge question, and scrub to prevent sql injection, but I'd say that Part I is done! (Or at least I don't think I need any more help with that.)

Now, onto displaying the data on the main page of the site. I may already have enough info to do this.  I know with MS SQL Server, there was always tricky coding involved when datetime was used, and hope mySQL is more tame and/or plays nice. I will need to use datetime to sort the records, so I can display the newest 10 records, or whatever number that I decide.

I will come back to this thread and report if I have got it, and close the thread, or will come back with further questions. So far, so good. I think the hard part is done. So, thanks a million for hanging in there with me!

dtleahyAuthor Commented:
jason1178 said:
Whenever you generate an email from a script it raises the spam profile considerably.  Machine-generated messages can get dumped outright by many, many receiving servers depending on how reputable your ISP is.  Check some of the open relay blacklists and spam blacklists to see if your ISP has been reported for bad behavior by some of their users.  If so, time to find a new ISP.

In my reading, I found reference to the fact that Hotmail will not receive a message generated by the php mail() function. I find that impossible to believe, but it shows others are seeing a problem (and what are the odds they are trying from the same hosting company.)

Supposedly (and this makes sense), the spam filters look for messages that obviously appear spoofed. The way WebHostingHub sends out email, it is using my main email account, and I can't change that behavior - and don't want to use that (admin) email address at all in the headers. I did create another email account, and put that in the "from" and "reply-to" headers, but from the mailserver logs the hosting company tech was reading, I think it still has the main/admin email account listed in the path.

This is really a different issue, a "sub-issue" from this thread, and probably deserves a separate question at EE. I will do that.
Jason C. LevineDon't talk to me.Commented:

It's always a pleasure to help someone who takes the advice given and develops their skills from there.
Jason C. LevineDon't talk to me.Commented:
"I found reference to the fact that Hotmail will not receive a message generated by the php mail() function. I find that impossible to believe"

It's not quite that cut and dried but yes, Hotmail (and Yahoo for that matter) reject a very high percentage of machine-generated email.

What you can do is switch to a different mail function.  PHP has a ton of libraries via PEAR that do full SMTP with authentication.  Additionally/Alternately it might be worth switching to something like Amazon Simple Email Service and not rely on sketchy ISP email.
dtleahyAuthor Commented:
Looking into PEAR right now... (after dentist appointment, that is) SMTP authentication. Looks promising:

sample code:
 require_once "Mail.php";
 $from = "Sandra Sender <>";
 $to = "Ramona Recipient <>";
 $subject = "Hi!";
 $body = "Hi,\n\nHow are you?";
 $host = "";
 $username = "smtp_username";
 $password = "smtp_password";
 $headers = array ('From' => $from,
   'To' => $to,
   'Subject' => $subject);
 $smtp = Mail::factory('smtp',
   array ('host' => $host,
     'auth' => true,
     'username' => $username,
     'password' => $password));
 $mail = $smtp->send($to, $headers, $body);
 if (PEAR::isError($mail)) {
   echo("<p>" . $mail->getMessage() . "</p>");
  } else {
   echo("<p>Message successfully sent!</p>");

Open in new window

dtleahyAuthor Commented:
I jumped ahead to doing the final step, returning the data from the database and displaying it the way I wanted, showing the latest 10 validated people who had signed, stuffed into a listbox showing 4 rows (for space considerations on the webpage.)

I also had a couple of conditionals to deal with: user may or may not have a middle name/initial (NULL is ok), and I also wanted to designate US addresses as 'signer' and non-us addresses as 'supporter.'

I learned a lot about php, mySql, mySqlAdmin along the way...

In case anyone finds this in an EE search, looking for help related to this stuff, here is code that will fill a select, with conditionals:
//code for dbfillselect.php        
include "myconnection.php";  //a php file that does the database connection
$sql =  "SELECT xyzuserid, xyzvalid, xyzfname, xyzmname, xyzlname, xyzcity, xyzstate, xyzcountry FROM xyzsigners WHERE xyzvalid=1 ORDER BY xyzdatetime DESC LIMIT 0 , 10";

$result = mysql_query($sql);  
<select name="signerslist" id="Select1" size="4" style="width: 100%;">
    while($row = mysql_fetch_array($result))  
		if (empty($row['xyzmname']))
			$fullname=$row['xyzfname'].' '.$row['xyzlname'];
	  		$fullname=$row['xyzfname'].' '.$row['xyzmname'].' '.$row['xyzlname'];
		if (strtolower($row['xyzcountry'])=="united states of america")
			$sigsup=" - Signer";
			$sigsup=" - Supporter";
		$signer=$fullname.', '.$row['xyzcity'].', '.$row['xyzstate'].', '.$row['xyzcountry'].$sigsup;		 
    <option value="<?php echo $row['xyzfname']; ?>">  
				## a normal listbox would store id but I don't want to expose ids $row['xyzuserid']; 
				echo $signer;  

Open in new window

Credit to Tolinio Christodoulou  at this site:
as this was the code I started with, and modified.

...and now, back to PEAR...

dtleahyAuthor Commented:
Thanks to Jason and Ray for all the help!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.