0

Hi all,

I have a registration page which allows the user to open up separate windows to include additional information. But for some reason it freezes the page and doesn’t allow data to be submitted into the MySQL database table. I’m mot sure whether this is a php or a JavaScript problem could be both . I have included code samples so you could all get a better understanding of the problem. Also the windows appear when the page loads and not when clicked which is how its suppose to function. Appear when clicked, not when the page has loaded. Your help will be greatly appreciated . Thanks all

stylesheet.css

body {
    font-family: "trebuchet ms", verdana, sans-serif;
    font-size: 12px;
    line-height: 1.5em;
    color: #333;
    background: #ffffff;
    margin: 0;
    padding: 0;
    text-align: center;
    width: 100%;
}


#container {
    position: absolute;
    top: 140px;
    left: 0px;
    background: #ffffff;
    margin: 0 auto 0 auto;
    text-align: left;
    width: 100%;
    height: 100%;
}


#main {
    margin: 15px 15px 15px 240px;
    padding: 15px 15px 15px 15px;
    background: #FFFFFF;

}


table {
    border: thin solid blue;
    background: #ffffff;
}

th {
    letter-spacing: 2.5px;
    background: #eeeeeee;
    color: #000000;
    text-transform: uppercase;
    text-align: center;
    border-top: thick solid #eeeeee;
    border-bottom: thin solid #cccccc;
}

.register {

    position: absolute;
    border: thin solid #cccccc;
    background: #ffffff;
    top:  100px;
    left: 255px;

}

.table1 {
        position: absolute;
        width: 500px;
        border: thin solid #cccccc;
    background: #ffffff;
    top:  360px;
    left: 302px; 


}

.table2 {
        position: absolute;
        width: 500px;
    border: thin solid #cccccc;
    background: #ffffff;
    top:  382px;
    left: 302px; 


}
label.texts {
    color: #ffffff;
}

// testsite.SQL

create database testsite;
use testsite;

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `gender` varchar(16) NOT NULL,
  `registration_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; 



CREATE TABLE IF NOT EXISTS `register` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `username` varchar(10) NOT NULL,
  `password` varchar(255) NOT NULL,
  `title` varchar(9) NOT NULL,
  `firstname` varchar(20) NOT NULL,
  `surname` varchar(40) NOT NULL,
  `addresstype` varchar(9) NOT NULL,
  `address` varchar(100) NOT NULL,
  `postalcode` varchar(9) NOT NULL,
  `state` varchar(50) NOT NULL,
  `city` varchar(30) NOT NULL,
  `country` varchar(30) NOT NULL,
  `tel` varchar(16) NOT NULL,
  `mobile` varchar(16) NOT NULL,
  `fax` varchar(16) NOT NULL,
  `email` varchar(100) NOT NULL,
  `website` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

// config.php

<?php            
$dbhost = "localhost";
$dbuser = "root";
$dbpassword = "";
$dbdatabase = "testsite";

// Add the location   
$config_basedir = "http://localhost/testsite/";

$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);

?>

// header.php

<?php


require("config.php");
header("content-type: application/x-javascript");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>

    <title></title>
    <style type="text/css">
    h4, b {color: #ff0000; font-family: ariel;}
    p {text-indent: 0cm; background: ffffff; font-family: courier;}
    </style>
    <link rel="stylesheet" href="stylesheet.css" type="text/css"/>   


</head>   




<div id="container">


<div id="main">



// register.php

<?php 
 require("config.php"); 
if(isset($_POST['submit']) == TRUE) {

// username Validation 
    if(!empty($_POST['username'])) 
    { 
        $username = strip_tags(mysql_real_escape_string($_POST['username']));   
    } 
    else
    {
        echo "Please enter username";
        exit();
    }


// password Validation  
    if(!empty($_POST['password1'])) 
    { 
        $password1 = strip_tags(mysql_real_escape_string($_POST['password1'])); 
        $passwordcrypted = sha1($password1);        
    } 
    else
    {
        echo "Please enter password";
        exit();
    }   


// password2 Validation 
    if(!empty($_POST['password2']))   
    { 
        $password2 = strip_tags(mysql_real_escape_string($_POST['password2']));             
    }
    else
    { 
        echo "Please re enter password";
        exit(); 
    }



// title Validation 
    if(!empty($_POST['title'])) 
    { 
        $title = strip_tags(mysql_real_escape_string($_POST['title']));     
    } 
    else
    {
        echo "Please enter title";
        exit();
    }



// firstname Validation 
    if(!empty($_POST['firstname'])) 
    {
        $firstname = strip_tags(mysql_real_escape_string($_POST['firstname']));
    }
    else
    { 
        echo "Please enter firstname";
        exit();
    }


// surname Validation
    if(!empty($_POST['surname'])) 
    { 
        $surname = strip_tags(mysql_real_escape_string($_POST['surname']));
    }
    else
    {
        echo "Please enter surname";
        exit();
    }


// gender Validation
if(!empty($_POST['gender'])) 
    { 
        $gender = strip_tags(mysql_real_escape_string($_POST['gender']));   
    } 
    else
    {
        echo "Please enter gender";
        exit();
    }


// addresstype Validation
    if(!empty($_POST['addresstype'])) 
    { 
        $addresstype = strip_tags(mysql_real_escape_string($_POST['addresstype'])); 
    }
    else
    { 
        echo "Please enter address type";
        exit();
    }


// address Validation
    if(!empty($_POST['address']))
    { 
        $address = strip_tags(mysql_real_escape_string($_POST['address'])); 
    }
    else    
    { 
        echo "Please enter address";
        exit();
    } 


// postalcode Validation        
    if(!empty($_POST['postalcode'])) 
    {
        $postalcode = strip_tags(mysql_real_escape_string($_POST['postalcode']));       
    } 
    else
    { 
        echo "Please enter postalcode";
        exit(); 
    }


// city Validation
    if(!empty($_POST['city'])) 
    { 
        $city = strip_tags(mysql_real_escape_string($_POST['city']));   
    }
    else
    {
        echo "Please enter city";
        exit();
    }


// state Validation
    if(!empty($_POST['state'])) 
    { 
        $state = strip_tags(mysql_real_escape_string($_POST['state'])); 
    }
    else
    {
        echo "Please enter state";
        exit();
    }


// country Validation
    if(!empty($_POST['country']))  
    {
        $country = strip_tags(mysql_real_escape_string($_POST['country']));     
    }
    else
    { 
        echo "Please enter country";
        exit();
    }


// tel Validation 

    if(!empty($_POST['tel']))   
    { 
        $tel = strip_tags(mysql_real_escape_string($_POST['tel'])); 
    }
    else    
    {
        echo "Please enter tel";
        exit();
    } 



// mobile Validation
    if(!empty($_POST['mobile']))
    {
        $mobile = strip_tags(mysql_real_escape_string($_POST['mobile']));
    }
    else    
    {
        echo "Please enter mobile";
        exit();
    }


// fax Validation
    if(!empty($_POST['fax']))
    {
        $fax = strip_tags(mysql_real_escape_string($_POST['fax']));
    }
    else    
    {
        echo "Please enter fax";
        exit();
    }


// email Validation
    if(!empty($_POST['email']))
    {
        $email = strip_tags(mysql_real_escape_string($_POST['email']));
    } 
    else
    {
        echo "Please enter email";
        exit();
    }

//  website Validation

    if(!empty($_POST['website']))
    {
        $website = strip_tags(mysql_real_escape_string($_POST['website']));
    } 
    else
    {
        echo "Please enter website";
        exit();
    }


        if($password1 == $password2) {


      $usersql = "INSERT INTO users(gender) 
      VALUES('" . addslashes($gender) 
      . "');";
      echo $usersql;        
            mysql_query($usersql)or die(mysql_error());  
          $userid = mysql_insert_id();  

       header("Location: " . $config_basedir . "/register.php?id=".$userid); 

            $sql = "INSERT INTO register(user_id, username, password, title, firstname, surname, addresstype, address, postalcode, city, state, country, tel, mobile, fax, email, website, verifystring, active) 
        VALUES(" . $userid
        . ",  '" . addslashes($username)
        . "', '" . ($passwordcrypted) 
        . "', '" . addslashes($title)
        . "', '" . addslashes($firstname)
        . "', '" . addslashes($surname)             
        . "', '" . addslashes($addresstype)
        . "', '" . addslashes($address)             
        . "', '" . addslashes($postalcode)             
        . "', '" . addslashes($city)
        . "', '" . addslashes($state)
        . "', '" . addslashes($country)
        . "', '" . addslashes($tel)
        . "', '" . addslashes($mobile)
        . "', '" . addslashes($fax) 
        . "', '" . addslashes($email) 
        . "', '" . addslashes($website)
        . "', '" . addslashes($randomstring) 
        . "', 0);";
        //  echo $sql;      
            mysql_query($sql)or die(mysql_error());  


        }
    }
    require("header.php");
?>

<style type="text/css">
</style>
<script type="text/javascript">
window.onload=setup;

function setup() {
   document.getElementById('one').style.display='none';
   document.getElementById('two').style.display='none';
    document.getElementById('three').style.display='none';
     document.getElementById('four').style.display='none';
      document.getElementById('five').style.display='none';
       document.getElementById('six').style.display='none';
        document.getElementById('seven').style.display='none';
        document.getElementById('eight').style.display='none';


}

function show(newItem) {
   var item = document.getElementById(newItem);
   if (item.style.display=='none') {
       item.style.display='block';
   } else {
       item.style.display='none';
   }
}
</script>

<?php

echo "<hr></hr>";
  echo "<h1><label class='titleBlue'>Create an account and become a member</label></h1>";
echo "<hr></hr>";
?>  

    <form action="" method="POST">
    <table>
    <tr>
    <td  colspan="2" bgcolor="#0000CD"> <label class="texts"><strong>To register  fill in the form below.<br /></strong></label></td>
 </tr>   

    <tr>
        <td>Username &#160; &#42</td>
        <td><label for="username"><input  STYLE="foreground:#ffffff; color:#eaeaea; type="text" name="username"id="username"size="10" maxlength="20"value="bob"onfocus="clearMe(this)" class="reqd username"/> Username can be upto 10 charcters in length</label></td>
    </tr>
    <tr>
        <td>Password &#160; &#42</td>
        <td><label for="password1"><input type="password" name="password1"id="password1"size="10" maxlength="20"value="passwordy"onfocus="clearMe(this)" class="reqd password1"/></label> Password can be upto 20 charcters in length</td>
    <tr>
        <td>Re-enter Password &#160; &#42</td>
        <td><label for="password2"><input type="password" name="password2"id="password2"size="10" maxlength="20"value="passwordy"onfocus="clearMe(this)" class="reqd password2"/></label></td>
    </tr>
        <tr>
                <td>&#032;</td>   
        <td>            
                              <select name="title">                                
                                     <option>Title</option>
                                     <option>Mr</option>
                                     <option>Mrs</option>
                                     <option>Miss</option>
                                     <option>Ms</option>
                                     <option>Dr</option>                                       
                            </select>  
                </td>
            </tr>
            <tr>
        <td>Firstname &#160; &#42</td>
        <td><label for="firstname"><input STYLE="foreground:#ffffff; color:#eaeaea; type="text" name="firstname"id="firstname"size="10" maxlength="20"value="paul"onfocus="clearMe(this)" class="reqd firstname"/></label></td>
    </tr>
    <tr>
        <td>Surname &#160; &#42</td>
        <td><label for="surname"><input STYLE="foreground:#ffffff; color:#eaeaea; type="text" name="surname"id="surname"size="10" maxlength="20"value="paula"onfocus="clearMe(this)" class="reqd surname"/></label></td>
    </tr>
    <tr>
                <td width="180"><strong>Gender &#160; &#42</strong></td>
                <td><label class="titleBlue"><input type="radio" name="gender" value="Male"/><strong>Male</strong></label>    
                    <label class="pink"><strong><input type="radio" name="gender" value="Female"/>Female</strong></label>
                    <label class="noRed"><strong><input type="radio" name="gender" value="Rather not say" checked="checked"/>rather not say</strong></label>
                    </tr>    

 </table>


 <div class="label" onclick="show('two')"><strong>Click here to open/close more options(1)</strong></div>

     <div class="elements" id="two">
     <table class="table1">
        <tr>
    <td  colspan="2" bgcolor="#0000CD"> <label class="texts"><strong>Address details Business/Home.</strong></label></td>
 </tr>
        <tr>  
                <td>&#032;</td>    
        <td>            
                      <select name="addresstype">                                  
                                 <option>Address Type</option>
                                 <option>Home</option>
                                 <option>Business</option>                                                                     
                        </select>  
                </td>
            </tr>
    <tr>
        <td>Address &#160; &#42</td>
        <td><label for="address"><input STYLE="foreground:#ffffff; color:#eaeaea; type="text" name="address" id="address" size="50" maxlength="100" value="27 flatbush" onfocus="clearMe(this)" class="reqd address"/></label></td>
    </tr>
    <tr>
        <td>Post/zip code &#160; &#42</td>
        <td>
        <label for="postalcode"><input STYLE="foreground:#ffffff; color:#eaeaea; type="text" name="postalcode" id="postalcode" size="12" maxlength="7"value="w34er"onfocus="clearMe(this)" class="reqd postalcode"/></label></td>
    </tr>

    <tr>
        <td>City &#160; &#42</td>
        <td><label for="city"><input STYLE="foreground:#ffffff; color:#eaeaea; type="text" name="city"id="city"size="20" maxlength="30"value="london"onfocus="clearMe(this)" class="reqd city"/></label></td>
    </tr>
    <tr>
        <td>State</td>
        <td><label for="state"><input STYLE="foreground:#ffffff; color:#eaeaea; type="text" name="state" id="state"
            size="20" maxlength="30" value="state" value="<?php if (isset($trimmed['state'])) echo $trimmed['state']; ?>" onfocus="clearMe(this)"
            class="reqd state" /></td>
    </tr>
     <tr>
        <td>Country &#160; &#42</td>
        <td><select name="country">
                    <option>EUROPE</option>
            <option>Austria</option>
<option>Belgium</option>
<option>Bulgaria</option>
<option>Canada</option>
<option>Cyprus</option>
<option>Czech Republic</option> 
<option>Denmark</option>
<option>Estonia</option>
<option>Finland</option>
<option>France</option>
<option>Germany</option>
<option>Greece</option>
<option>Hungary</option>
<option>Ireland</option>
<option>Italy</option>
<option>Latvia</option>
<option>Lithuania</option>
<option>Luxembourg</option>
<option>Malta</option>
<option>Netherlands</option>
<option>Poland</option>
<option>Portugal</option>
<option>Romania</option>
<option>Slovakia</option>
<option>Slovenia</option>
<option>Sweden</option>
<option>United Kingdom</option>
<option>United States</option>    
        </select></td>
    </tr>
     </table>   
    </div>


 <div class="label" onclick="show('three')"><strong>Click here to open/close more options(2)</strong></div>

     <div class="elements" id="three">
     <table class="table2">  
    <tr> 
    <td  colspan="2" bgcolor="#0000CD"> <label class="texts"><strong>Contact details. Use hyphen to serperate numbers eg 0207-123-4567</strong></label></td>
 </tr>
    <tr>
        <td>Tel &#160; &#42</td>
        <td><label for="tel"><input STYLE="foreground:#ffffff; color:#eaeaea; type="text" name="tel"id="tel" size="16" maxlength="30"value="02043456789"onfocus="clearMe(this)" class="reqd tel"/></label></td>
    </tr>
    <tr>
        <td>Mobile</td>
        <td><label for="mobile"><input STYLE="foreground:#ffffff; color:#eaeaea; type="text" name="mobile"id="mobile" size="16" maxlength="30"value="02043456789"onfocus="clearMe(this)" class="reqd mobile"/></label></td>
    </tr>
    <tr>
        <td>Fax</td>
        <td><label for="fax"><input STYLE="foreground:#ffffff; color:#eaeaea; type="text" name="fax"id="fax" size="16" maxlength="30"value="02043456789"onfocus="clearMe(this)" class="reqd fax"/></label></td>
    </tr>
    <tr>
        <td>Email &#160; &#42</td>
        <td><label for="email"><input  STYLE="foreground:#ffffff; color:#eaeaea; type="text" name="email"id="email"size="50" maxlength="100"value="demo@localhost.com"onfocus="clearMe(this)" class="reqd email"/></label></td>
    </tr>
    <tr>
        <td>Website URL - optional</td>                                                                     
        <td><input type="text" STYLE="foreground:#ffffff; color:#eaeaea; type="text" name="website" id="website"size="40" maxlength="100" value="www.baydocks.com" onfocus="clearMe(this)"/>(Recommended)</td>
    </tr>
    <tr>
    <td>&#032;</td>
        <td align = right><input type="submit" name="submit"id="submit" value="Register!"/></td>
    </tr>
     </table>   
    </div>

    </form>

Edited by codeblock

1
Contributor
1
Reply
2
Views
5 Years
Discussion Span
Last Post by codeblock
0

replace previous code snippet with this guys

            $sql = "INSERT INTO register(user_id, username, password, title, firstname, surname, addresstype, address, postalcode, city, state, country, tel, mobile, fax, email, website) 
        VALUES(" . $userid
        . ",  '" . addslashes($username)
        . "', '" . ($passwordcrypted) 
        . "', '" . addslashes($title)
        . "', '" . addslashes($firstname)
        . "', '" . addslashes($surname)             
        . "', '" . addslashes($addresstype)
        . "', '" . addslashes($address)             
        . "', '" . addslashes($postalcode)             
        . "', '" . addslashes($city)
        . "', '" . addslashes($state)
        . "', '" . addslashes($country)
        . "', '" . addslashes($tel)
        . "', '" . addslashes($mobile)
        . "', '" . addslashes($fax) 
        . "', '" . addslashes($email) 
        . "', '" . addslashes($website)
        . "', 0);";
        //  echo $sql;      
            mysql_query($sql)or die(mysql_error()); 
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.