Solved

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

Posted on 2012-03-20
29
571 Views
Last Modified: 2012-03-25
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.
0
Comment
Question by:dtleahy
  • 16
  • 9
  • 3
29 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
Comment Utility
Do you have any scripting knowledge or are you asking us to give you a complete, ready-to-go solution?
0
 

Author Comment

by:dtleahy
Comment Utility
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.

Dennis
0
 
LVL 70

Expert Comment

by:Jason C. Levine
Comment Utility
>> 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?
0
 

Author Comment

by:dtleahy
Comment Utility
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.

Dennis
0
 
LVL 70

Assisted Solution

by:Jason C. Levine
Jason C. Levine earned 286 total points
Comment Utility
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.
0
 

Author Comment

by:dtleahy
Comment Utility
Awesome! Thanks for your help, Jason.

Here is the beginnings of the input form: http://www.resetbutton2012.org/RB2012form.html

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.

Dennis
0
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 286 total points
Comment Utility
>> 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:

http://www.phpeveryday.com/articles/PHP-MySQL-Creating-Form-Insert-Data-P280.html

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

<?php

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

// 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:

http://www.siteground.com/tutorials/php-mysql/display_table_data.htm
0
 

Author Comment

by:dtleahy
Comment Utility
<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.

Dennis
0
 
LVL 70

Expert Comment

by:Jason C. Levine
Comment Utility
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.
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 214 total points
Comment Utility
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.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_9849-Making-CAPTCHA-Friendlier-with-PHP-Image-Manipulation.html
0
 

Author Comment

by:dtleahy
Comment Utility
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...

Dennis
0
 
LVL 70

Expert Comment

by:Jason C. Levine
Comment Utility
"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.
0
 

Author Comment

by:dtleahy
Comment Utility
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.
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 214 total points
Comment Utility
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.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:dtleahy
Comment Utility
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...

<?php
$username="myrealusername";
$password="abc!123";
$database="therealdatabase";


$rbname=$_POST['v_name'];
$rbcity=$_POST['v_city'];
$rbstate=$_POST['v_state'];
$rbcountry=$_POST['v_country'];
$rbemail=$_POST['v_email'];
$rbip=$_POST['ipaddy'];
$rbokemail=$_POST['v_chkok'];

mysql_connect(localhost,$username,$password);
@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')";

mysql_query($query);

mysql_close();
?>

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.
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 214 total points
Comment Utility
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
error_reporting(E_ALL);


// THE ABSOLUTE MINIMUM YOU MUST UNDERSTAND TO USE PHP AND MYSQL
// MAN PAGE: http://php.net/manual/en/ref.mysql.php
// MAN PAGE: http://php.net/manual/en/mysql.installation.php
// MAN PAGE: http://php.net/manual/en/function.mysql-connect.php
// MAN PAGE: http://php.net/manual/en/function.mysql-select-db.php
// MAN PAGE: http://php.net/manual/en/function.mysql-real-escape-string.php
// MAN PAGE: http://php.net/manual/en/function.mysql-query.php
// MAN PAGE: http://php.net/manual/en/function.mysql-errno.php
// MAN PAGE: http://php.net/manual/en/function.mysql-error.php
// MAN PAGE: http://php.net/manual/en/function.mysql-num-rows.php
// MAN PAGE: http://php.net/manual/en/function.mysql-fetch-assoc.php
// MAN PAGE: http://php.net/manual/en/function.mysql-fetch-array.php
// MAN PAGE: http://php.net/manual/en/function.mysql-insert-id.php



// CONNECTION AND SELECTION VARIABLES FOR THE DATABASE
$db_host = "localhost"; // PROBABLY THIS IS OK
$db_name = "??";        // GET THESE FROM YOUR HOSTING COMPANY
$db_user = "??";
$db_word = "??";


// OPEN A CONNECTION TO THE DATA BASE SERVER
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/>";
}

// SELECT THE MYSQL DATA BASE
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');
}
// IF THE SCRIPT GETS THIS FAR IT CAN DO QUERIES

Open in new window

0
 

Author Comment

by:dtleahy
Comment Utility
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_
0
 

Author Comment

by:dtleahy
Comment Utility
Here is a resource I just found for my next steps...

(Email activation for php forms)

http://www.learnphponline.com/scripts/email-activation-for-php-forms

Dennis
0
 

Author Comment

by:dtleahy
Comment Utility
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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<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" />
</head>
<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>
		<div>
			<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>
		<div>
			<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>
		<div>
			<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>
		<div>
		<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>


		</select>
		</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>
		<div>
			<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>
		<span>
			<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>
			
					<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" />
		</li>
			</ul>
		</form>	
		<div id="footer">
			might want to add a footer message
		</div>
	</div>
	<img id="bottom" src="Images/rb2012formbottom.png" alt="" />
	</body>
</html>

Open in new window


and the processing page:
<?php
$username="myusername";
$password="123!xyz";
$database="mydatabase";


$xname=$_POST['v_name'];
$xcity=$_POST['v_city'];
$xstate=$_POST['v_state'];
$xcountry=$_POST['v_country'];
$xuseremail=$_POST['v_email'];
$xuserid=$_POST['ipaddy'];
$xokemail=$_POST['v_chkok'];

echo "name= " $xname

echo "email= " $xuseremail

echo "email ok= " $xokemail

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


mysql_connect(localhost,$username,$password);
@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 = " ResetButton2012.org Authentication (and Signing)";

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

$headers = 'From: webmaster@ResetButton2012.org' . "\r\n" .

    'Reply-To: webmaster@ResetButton2012.org' . "\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());

  			}

    }

  }

}


mysql_close();
?>

Open in new window

0
 

Author Comment

by:dtleahy
Comment Utility
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 WebHostingHub.com and now I'm wondering if I am always going to have trouble sending email from there.

Dennis
0
 
LVL 70

Assisted Solution

by:Jason C. Levine
Jason C. Levine earned 286 total points
Comment Utility
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.
0
 

Author Comment

by:dtleahy
Comment Utility
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!

Dennis
0
 

Author Comment

by:dtleahy
Comment Utility
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.
0
 
LVL 70

Expert Comment

by:Jason C. Levine
Comment Utility
Dennis,

It's always a pleasure to help someone who takes the advice given and develops their skills from there.
0
 
LVL 70

Assisted Solution

by:Jason C. Levine
Jason C. Levine earned 286 total points
Comment Utility
"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.
0
 

Author Comment

by:dtleahy
Comment Utility
Looking into PEAR right now... (after dentist appointment, that is) SMTP authentication. Looks promising:

sample code:
<?php
 require_once "Mail.php";
 
 $from = "Sandra Sender <sender@example.com>";
 $to = "Ramona Recipient <recipient@example.com>";
 $subject = "Hi!";
 $body = "Hi,\n\nHow are you?";
 
 $host = "mail.example.com";
 $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

0
 

Author Comment

by:dtleahy
Comment Utility
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:
<?php    
//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%;">
  
    <?php     
    while($row = mysql_fetch_array($result))  
	 	{		
		$signer='';
		
		if (empty($row['xyzmname']))
         {
			$fullname=$row['xyzfname'].' '.$row['xyzlname'];
			}
     else
	  		{
	  		$fullname=$row['xyzfname'].' '.$row['xyzmname'].' '.$row['xyzlname'];
			}
		if (strtolower($row['xyzcountry'])=="united states of america")
			{
			$sigsup=" - Signer";
			}
		else
			{
			$sigsup=" - Supporter";
			}
		$signer=$fullname.', '.$row['xyzcity'].', '.$row['xyzstate'].', '.$row['xyzcountry'].$sigsup;		 
    ?>  
  
  			
    <option value="<?php echo $row['xyzfname']; ?>">  
  
        <?php   				
				## a normal listbox would store id but I don't want to expose ids $row['xyzuserid']; 
				echo $signer;  
        ?>  
  
    </option>  
  
    <?php     
    }     
    ?>  
  
</select> 

Open in new window

Credit to Tolinio Christodoulou  at this site: http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=458&lngWId=8
as this was the code I started with, and modified.

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

Dennis
0
 

Author Closing Comment

by:dtleahy
Comment Utility
Thanks to Jason and Ray for all the help!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now