Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Issue with user registration script (PHP, MYSQL and javascript help)

    Hello. I am currently attempting to create a user registration script that will only show certain fields depending on the country the user chooses.

    For example, if the user chooses United States a list of states will be shown.
    If a person selects Canada, a list of provinces will be shown instead.

    At the moment I have created some preliminary code; however, I am experiencing two major problems.

    First the javascript does not hide anything until the user has changed the default country. That means that means all dependent variables are showing when the user first loads the page (which I don't want).

    The second issue is when the user actually signs up the script does not recognize if the user was from a different country. If a person has selected a province, it still adds the default "state" to the database. Below is the code. Any help you can provide is appreciated.

    JavaScript Code
    Code:
    <script language="JavaScript" type="text/javascript">
    <!--
    
    function display(obj,id,id2,id3,id4){
     txt=obj.options[obj.selectedIndex].text;
     if (txt.match('United States')){
      document.getElementById(id).style.display = 'block';
     document.getElementById(id2).style.display = 'none';
    document.getElementById(id3).style.display = 'none';
    document.getElementById(id4).style.display = 'none';
     }
    if (txt.match('Canada')){
      document.getElementById(id2).style.display = 'block';
    document.getElementById(id).style.display = 'none';
    document.getElementById(id3).style.display = 'none';
    document.getElementById(id4).style.display = 'none';
     }
    if (txt.match('Mexico')){
      document.getElementById(id2).style.display = 'none';
    document.getElementById(id).style.display = 'none';
    document.getElementById(id3).style.display = 'block';
    document.getElementById(id4).style.display = 'none';
     }
    if (txt.match('Other')){
      document.getElementById(id2).style.display = 'none';
    document.getElementById(id).style.display = 'none';
    document.getElementById(id3).style.display = 'none';
    document.getElementById(id4).style.display = 'block';
     }
    
    }
    
    //-->
    </script>
    HTML Code
    Code:
    <select name="country" onchange="display(this,'state','province','mstate','other');">
    <option value="Canada">Canada</option>
    <option value="Mexico">Mexico</option>
    <option value="Other">Other</option>
    <option value="United States">United States</option></tr></td>
    
    </select>
    
    
    <tr id="province"><td>&nbsp;&nbsp;&nbsp;&nbsp;Province*</td><td>
      <select id="province" name="locale">
    <option value="Alberta">Alberta</option>
    <option value="British Columbia">British Columbia</option>
    <option value="Manitoba">Manitoba</option>
    <option value="New Brunswick">New Brunswick</option>
    <option value="Newfoundland and Labrador">Newfoundland and Labrador</option>
    <option value="Nova Scotia">Nova Scotia</option>
    <option value="Ontario">Ontario</option>
    <option value="Prince Edward Island">Prince Edward Island</option>
    <option value="Saskatchewan">Saskatchewan</option>
    <option value="Quebec">Quebec</option>
    </select></td></tr>
    
    <tr id="other"><td >&nbsp;&nbsp;&nbsp;&nbsp;Country*</td><td ><font face='Verdana' size='2'><input type=text name=location></td></tr>
    <tr id="mstate"><td>&nbsp;&nbsp;&nbsp;&nbsp;State*</td><td>
      <select id="mstate" name="locale">
    <option value="Aguascalientes">Aguascalientes</option>
    <option value="Baja California">Baja California</option>
    <option value="Campeche">Campeche</option>
    <option value="Chiapas">Chiapas</option>
    <option value="Chihuahua">Chihuahua</option>
    <option value="Coahuila">Coahuila</option>
    <option value="Colima">Colima</option>
    <option value="Distrito Federal">Distrito Federal</option>
    <option value="SDurango">SDurango"</option>
    <option value="Guanajuato">Guanajuato</option>
    <option value="Guerrero">Guerrero</option>
    <option value="Hidalgo">Hidalgo</option>
    <option value="Jalisco">Jalisco</option>
    <option value="México">México</option>
    <option value="Michoacán">Michoacán</option>
    <option value="Morelos">Morelos</option>
    <option value="Nayarit">Nayarit</option>
    <option value="Nuevo León">Nuevo León</option>
    <option value="Oaxaca">Oaxaca</option>
    <option value="Puebla">Puebla</option>
    <option value="Querétaro">Querétaro</option>
    <option value="Quintana Roo">Quintana Roo</option>
    <option value="San Luis Potosí">San Luis Potosí</option>
    <option value="Sinaloa">Sinaloa</option>
    <option value="Sonora">Sonora</option>
    <option value="Tabasco">Tabasco</option>
    <option value="Tamaulipas">Tamaulipas</option>
    <option value="Tlaxcala">Tlaxcala</option>
    <option value="Veracruz">Veracruz</option>
    <option value="Yucatán">Yucatán</option>
    <option value="Zacatecas">Zacatecas</option>
    </select></td></tr>
    
    
    <tr id="state"><td>&nbsp;&nbsp;&nbsp;&nbsp;State*</td><td>
    <select id="state" name="locale">
    <option value="Alabama">Alabama</option>
    <option value="Alaska">Alaska</option>
    <option value="Arizona">Arizona</option>
    <option value="Arkansas">Arkansas</option>
    <option value="California">California</option>
    <option value="Colorado">Colorado</option>
    <option value="Connecticut">Connecticut</option>
    <option value="Delaware">Delaware</option>
    <option value="Florida">Florida</option>
    <option value="Georgia">Georgia</option>
    <option value="Hawaii">Hawaii</option>
    <option value="Idaho">Idaho</option>
    <option value="Illinois">Illinois</option>
    <option value="Indiana">Indiana</option>
    <option value="Iowa">Iowa</option>
    <option value="Kansas">Kansas</option>
    <option value="Kentucky">Kentucky</option>
    <option value="Louisiana">Louisiana</option>
    <option value="Maine">Maine</option>
    <option value="Maryland">Maryland</option>
    <option value="Massachusetts">Massachusetts</option>
    <option value="Michigan">Michigan</option>
    <option value="Minnesota">Minnesota</option>
    <option value="Mississippi">Mississippi</option>
    <option value="Missouri">Missouri</option>
    <option value="Montana">Montana</option>
    <option value="Nebraska">Nebraska</option>
    <option value="Nevada">Nevada</option>
    <option value="New Hampshire">New Hampshire</option>
    <option value="New Jersey">New Jersey</option>
    <option value="New Mexico">New Mexico</option>
    <option value="New York">New York</option>
    <option value="North Carolina">North Carolina</option>
    <option value="North Dakota">North Dakota</option>
    <option value="Ohio">Ohio</option>
    <option value="Oklahoma">Oklahoma</option>
    <option value="Oregon">Oregon</option>
    <option value="Pennsylvania">Pennsylvania</option>
    <option value="Rhode Island">Rhode Island</option>
    <option value="South Carolina">South Carolina</option>
    <option value= "South Dakota">South Dakota</option>
    <option value="Tennessee">Tennessee</option>
    <option value="Texas">Texas</option>
    <option value="Utah">Utah</option>
    <option value="Vermont">Vermont</option>
    <option value="Virginia">Virginia</option>
    <option value="Washington\">Washington</option>
    <option value="West Virginia">West Virginia</option>
    <option value="Wisconsin">Wisconsin</option>
    <option value="Wyoming">Wyoming</option></td></tr>
    PHP CODE

    Code:
    <?php
    $uname=trim($_POST['userid']);
    $fname=$_POST['fname'];
    $lname=$_POST['lname'];
    $mname=$_POST['mname'];
    $password=$_POST['password'];
    $password2=$_POST['password2'];
    $email=$_POST['email'];
    $email2=$_POST['email2'];
    $country=$_POST['country'];
    $locale=$_POST['locale'];
    $city=$_POST['city'];
    $bday=$_POST['day'];
    $bmonth=$_POST['month'];
    $byear=$_POST['year'];
    $sex=$_POST['sex'];
    $agree=$_POST['agree'];
    $ip=$_SERVER['REMOTE_ADDR'];
    
    
    
    $status = "OK";
    $msg="";
    
    if (empty($_POST['userid'])) {
    $msg=$msg. "You must enter a user name<br>";
    $status = "NOTOK";
    }
    
    if (empty($_POST['fname'])){
    $msg=$msg. "You must enter your first name.<br>";
    $status = "NOTOK";
    }
    
    if (empty($_POST['lname'])){
    $msg=$msg. "You must enter your last name<br>";
    $status = "NOTOK";
    }
    
    if (empty($_POST['password'])){
    $msg=$msg. "You must enter a password.<br>";
    $status = "NOTOK";
    }
    
    if (empty($_POST['password2'])){
    $msg=$msg. "You must re-enter your password.<br>";
    $status = "NOTOK";
    }
    
    
    if (strpos($userText, " ") !== false) {
    $msg=$msg. "Your user name can not contain any spaces.<br>";
    $status="NOTOK";
    }
    
    
    if (empty($_POST['email'])){
    $msg=$msg. "You must enter your email.<br>";
    $status = "NOTOK";
    }
    
    if (empty($_POST['email2'])){
    $msg=$msg. "You must re-enter your email.<br>";
    $status = "NOTOK";
    }
    
    if(!isset($uname) or strlen($uname) <4){
    $msg=$msg."User name must be between 4 and 10 characters.<BR>";
    $status= "NOTOK";}
    
    if(!isset($uname) or strlen($uname) >10){
    $msg=$msg."User name must be between 4 and 10 characters.<BR>";
    $status= "NOTOK";}
    
    if($password != $password2){
    $msg=$msg. "Passwords do not match.  Passwords must match.  Try again<BR>";
    $status="NOTOK";}
    
    if($email != $email2){
    $msg=$msg. "Emails do not match.  Emails must match.  Try again<BR>";
    $status="NOTOK";}
    
    if($_POST['agree'] != "yes"){
    $msg=$msg. "You must agree to the terms and conditions";
    $status= "NOTOK";
    }
    
    
    $query = "SELECT * FROM USERS WHERE UNICK = '".mysql_real_escape_string($uname)."'";
    $result = mysql_query($query) or die('MySQL Error: '.mysql_error());
    if(mysql_num_rows($result)){
    $msg=$msg."User Name already exists. Please try another one<BR>";
    $status= "NOTOK";}
    
    $query = "SELECT * FROM USERS WHERE UEMAIL = '".mysql_real_escape_string($email)."'";
    $result = mysql_query($query) or die('MySQL Error: '.mysql_error());
    if(mysql_num_rows($result)){
    $msg=$msg."Email is already registered.  Only one account per email is allowed.<BR>";
    $status= "NOTOK";} 
    
    if ($status != "OK"){
    echo "<div style=\"position:relative; top:0; left:0; width:500; height:500; z-index:1;\">$msg<form>
    <input type=\"button\" value=\"Back to Previous Page\"
    onClick=\"javascript: history.go(-1)\">
    </form></div>";
    }else{
    $activation = md5(uniqid(rand(), true));
    $password = md5($password);
    
    if(mysql_query("insert into USERS(UID,UFNAME,UMNAME,ULNAME,UNICK,UGENDER,UPW,UEMAIL,UBDAY,UBMONTH,UBYEAR,UIP,UACTIVE,UCOUNTRY,ULOCALE,UCITY)
    values('NULL','$fname','$mname','$lname','$uname','$sex','$password','$email','$bday','$bmonth','$byear','$ip','$activation','$country','$locale','$city')")){
     $message = " Welcome to the BS Network!\r\rYou, or someone using your email address, has completed registration at thebsnetwork.org.\r You can complete registration by clicking the following link:\n\n";
    	                $message .= WEBSITE_URL . '/activate.php?email=' . urlencode($email) . "&key=$activation";
    	  
    $message .=  "\r\rPlease do not respond to this email.  This is an automated email generated through The BS Network's user registration program. \r\r If you have any questions, please contact support@thebsnetwork.org \r\r Thanks for registering! \r Sincerely, the BS Network.";
    mail($email, 'The BS Network Registration Confirmation', $message, 'From:'.EMAIL);
    echo "<div style=\"position:relative; top:0; left:0; width:500; height:500; z-index:1;\">Thank you for
    	registering! A confirmation email has been sent to $email <br>Please click on the Activation Link to Activate your account </div>";}
    else{ echo "Database Problem, please contact Site admin";
    //echo mysql_error();
    }
    }
    
    
    
    
    
    
    
    ?>
    Last edited by thebsnetwork; 03-30-2011 at 10:39 PM.

  • #2
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code
    Code:
    <?php
    $uname=trim($_POST['userid']);
    $fname=$_POST['fname'];
    $lname=$_POST['lname'];
    $mname=$_POST['mname'];
    $password=$_POST['password'];
    $password2=$_POST['password2'];
    $email=$_POST['email'];
    $email2=$_POST['email2'];
    $country=$_POST['country'];
    $locale=$_POST['locale'];
    $city=$_POST['city'];
    $bday=$_POST['day'];
    $bmonth=$_POST['month'];
    $byear=$_POST['year'];
    $sex=$_POST['sex'];
    $agree=$_POST['agree'];
    $ip=$_SERVER['REMOTE_ADDR'];
    
    
    
    $status = "OK";
    $msg="";
    
    if (empty($_POST['userid'])) {
    $msg=$msg. "You must enter a user name<br>";
    $status = "NOTOK";
    }
    
    if (empty($_POST['fname'])){
    $msg=$msg. "You must enter your first name.<br>";
    $status = "NOTOK";
    }
    
    if (empty($_POST['lname'])){
    $msg=$msg. "You must enter your last name<br>";
    $status = "NOTOK";
    }
    
    if (empty($_POST['password'])){
    $msg=$msg. "You must enter a password.<br>";
    $status = "NOTOK";
    }
    
    if (empty($_POST['password2'])){
    $msg=$msg. "You must re-enter your password.<br>";
    $status = "NOTOK";
    }
    
    
    if (strpos($userText, " ") !== false) {
    $msg=$msg. "Your user name can not contain any spaces.<br>";
    $status="NOTOK";
    }
    
    
    if (empty($_POST['email'])){
    $msg=$msg. "You must enter your email.<br>";
    $status = "NOTOK";
    }
    
    if (empty($_POST['email2'])){
    $msg=$msg. "You must re-enter your email.<br>";
    $status = "NOTOK";
    }
    
    if(!isset($uname) or strlen($uname) <4){
    $msg=$msg."User name must be between 4 and 10 characters.<BR>";
    $status= "NOTOK";}
    
    if(!isset($uname) or strlen($uname) >10){
    $msg=$msg."User name must be between 4 and 10 characters.<BR>";
    $status= "NOTOK";}
    
    if($password != $password2){
    $msg=$msg. "Passwords do not match.  Passwords must match.  Try again<BR>";
    $status="NOTOK";}
    
    if($email != $email2){
    $msg=$msg. "Emails do not match.  Emails must match.  Try again<BR>";
    $status="NOTOK";}
    
    if($_POST['agree'] != "yes"){
    $msg=$msg. "You must agree to the terms and conditions";
    $status= "NOTOK";
    }
    
    
    $query = "SELECT * FROM USERS WHERE UNICK = '".mysql_real_escape_string($uname)."'";
    $result = mysql_query($query) or die('MySQL Error: '.mysql_error());
    if(mysql_num_rows($result)){
    $msg=$msg."User Name already exists. Please try another one<BR>";
    $status= "NOTOK";}
    
    $query = "SELECT * FROM USERS WHERE UEMAIL = '".mysql_real_escape_string($email)."'";
    $result = mysql_query($query) or die('MySQL Error: '.mysql_error());
    if(mysql_num_rows($result)){
    $msg=$msg."Email is already registered.  Only one account per email is allowed.<BR>";
    $status= "NOTOK";} 
    
    if ($status != "OK"){
    echo "<div style=\"position:relative; top:0; left:0; width:500; height:500; z-index:1;\">$msg<form>
    <input type=\"button\" value=\"Back to Previous Page\"
    onClick=\"javascript: history.go(-1)\">
    </form></div>";
    }else{
    $activation = md5(uniqid(rand(), true));
    $password = md5($password);
    
    if(mysql_query("insert into USERS(UID,UFNAME,UMNAME,ULNAME,UNICK,UGENDER,UPW,UEMAIL,UBDAY,UBMONTH,UBYEAR,UIP,UACTIVE,UCOUNTRY,ULOCALE,UCITY)
    values('NULL','$fname','$mname','$lname','$uname','$sex','$password','$email','$bday','$bmonth','$byear','$ip','$activation','$country','$locale','$city')")){
     $message = " Welcome to the BS Network!\r\rYou, or someone using your email address, has completed registration at thebsnetwork.org.\r You can complete registration by clicking the following link:\n\n";
    	                $message .= WEBSITE_URL . '/activate.php?email=' . urlencode($email) . "&key=$activation";
    	  
    $message .=  "\r\rPlease do not respond to this email.  This is an automated email generated through The BS Network's user registration program. \r\r If you have any questions, please contact support@thebsnetwork.org \r\r Thanks for registering! \r Sincerely, the BS Network.";
    mail($email, 'The BS Network Registration Confirmation', $message, 'From:'.EMAIL);
    echo "<div style=\"position:relative; top:0; left:0; width:500; height:500; z-index:1;\">Thank you for
    	registering! A confirmation email has been sent to $email <br>Please click on the Activation Link to Activate your account </div>";}
    else{ echo "Database Problem, please contact Site admin";
    //echo mysql_error();
    }
    }
    
    
    
    
    
    
    
    ?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •