Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Realtime Form Validation 2

Status
Not open for further replies.

gasper000

Programmer
Nov 25, 2008
13
EG
Well, I have made a registration form & I want to apply the realtime validation process. I spent days searching online trying but it seems it's pretty hard for a beginner. I want client/server sides realtime validation to be able to validate the following:

1. Username: a)Checks if the username is already taken or still available.
b) Validates that the username is different from the Nickname, first name & last name.

2. Password: The form asks the user to type his password & then retypes it again. I want to validate that both entries are the same.

3. E-mail address: The form asks the user to type his email & then retypes it again. a) I want to validate that both entries are the same.
b) Checks if the email already registered before or not.
c) Validates the email format.

4. Nickname: a)Checks if the Nickname is already taken or still available.
b)Checks if the Nickname is different from the username, first name & last name.

5. First Name - Last Name: Validates that both are different from the Username & Nickname.

6. Country: Validates that the user IP is the same as the IP of the country he/she selected.

7. Birthdate: Validates that the user does not enter wrong date like 31/02/1999.

8. Validates the length of all the previous fields.



I know that's much work to do but even if you find it complicated or you have no time, you may drop some of the requirements (although all are important) or give me simple easy examples that are suitable for a beginner. That's really urgent. Thank you for your time.
 
This looks like a really standard piece of script, using JS for clientside and PHP for server side. You will find this helpful:

If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
I have been searching google for days. The problem is that this consists of 3 or 4 files. 1 of them is really long & hard to trace. Also they don't provide any description of the file names...Just some codes & scripts mixed together & as I'm a beginner I can't fix those codes by myself.
 
The Realtime client side validation would have to be done using Javascript.
And such you should ask this in the forum216

For the PHP part well I know you are a beginner, but you are not going to get a fully functional set of code to try out. So I suggest you start coding and come to us with more specific problems you may have while coding this.

Its really not difficult. You could even forgo the real time validation first and just check everything from PHP and then further down the line incorporate the Javascript. Neither should interfere with one another.

For starters here's and example on the user nickname, assuming you have already connected to the DB and the DB is MYSQL.

Code:
[green]//Get, and cleanse nickname variable submitted for usage in query[/green]
$nickname=mysql_real_escape_string($_POST['nickname']);

[green]//Create to check for existence of nickname in DB[/green]
$sql="SELECT *FROM myuserstable WHERE nickname=$nickname";
[green]//Execute query[/green]
$res=mysql_query($sql);

[green]//If any results are returned, you know the nickname is already taken.

if(mysql_num_rows>0){
echo "nickname already taken";
}

Now you can return to the form page and let the user try another nickname.






----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Here's an example I cobbled together.
It shows you how to validate the name against the nickname so they are not the same. Validate password field against confirmation password field so they are the same.
And checks for the existence of nickname in database.

I'm sure you can follow this and add the rest for the validation you require as they are only small variations.

I did also include some realtime JS validation for the name and nickname so they are not the same, but nothing more.


Code:
<html>
<head><title>Form Check</title>
<?PHP
//initiate variables needed later
$formvars=array();
$error=FALSE;

[green]//function to repopulate form fields in case of errors[/green]
function pop_field($fieldsarr=0,$field=0, $error=FALSE){
if($error==TRUE){
echo "value='" . $fieldsarr[$field] . "'";
}
else{
echo "value='...'";
}
}

[green]//check if form has been submitted[/green]
if(isset($_POST['formsent'])){
//connection to DB
include('dbconn.php');


[green]//clean all form variables so they can be used in queries for validation and insertion into DB [/green]
foreach($_POST as $key => $value){

$formvars[$key]=mysql_real_escape_string($value);

}

[green]//Initialize variables in case of errors.[/green]
$error=FALSE;
$errorstring='<span style="color:#FF0000;">Please Correct the following errors and try again:<br>';

[green]//Validate Form variables: [/green]
if($formvars['firstname']==$formvars['nickname']){
$error=TRUE;
$errorstring.="Nickname and Name can not be the same</br>";
}

if($formvars['pass_a']!=$formvars['pass_b']){
$error=TRUE;
$errorstring.="Password and Verify Password must be the same<br>";
}


[green]//check for existence of nickname in DB [/green]


$qry="SELECT name FROM keywords WHERE name='$formvars[nickname]'";
$res=mysql_query($qry) or die(mysql_error());
if(mysql_num_rows($res)>0){
$error=TRUE;
$errorstring.="Nickname already taken<br>";

}

$errorstring.="</span>";
if(!$error){
echo "Fields Submitted sucessfully...";
}

else{
echo $errorstring;
}
}
?>


</head>
<script language="JavaScript" type="text/javascript">
function validate(myform){

if(myform.firstname.value==myform.nickname.value){
alert("Name and Nickname cannot be the same");
return FALSE;
}


}

</script>
<body>
<form action=formceck.php method=POST OnSubmit="validate(this);">
Name:<input type=text name="firstname" <?PHP pop_field($formvars,'firstname',$error); ?> onblur="validate(document.forms[0]);"><br>
Nickname:<input type=text name="nickname" <?PHP pop_field($formvars,'nickname',$error); ?> onblur="validate(document.forms[0]);"><br>
Password:<input type=password name="pass_a" <?PHP pop_field($formvars,'pass_a',$error); ?>><br>
Retype:<input type=password name="pass_b" <?PHP pop_field($formvars,'pass_b',$error); ?>><br>
<input type=submit name="formsent" value="Submit Registration">
</form>





</body>
</html>

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
If you want to POST the values, then return to the page (per vacunita's suggestion), then you have some of that code that you'll need.

There are parts you won't want straight JS for, like username validation. You won't want to store all of the usernames in an array and search them.

For many of those questions, you should look into AJAX. It will allow you to remain in the same form, but check the database through a javascript function. You could check the database with every keystroke (onChange event, or when they leave the input field (onBlur).

Mark
 
Thanks a lot for your time & effort. I have tried the codes but still it's not working. I tried editing it but actually I'm really tired & it's late here, so I will go sleep & try again tomorrow. In case it doesn't work, I will send here the form codes, may be that help.

I voted for you. Thanks again for your effort.
 
The script assumes several things:

The connection to a DB: I used MYSQL but if you are using something else you 'll have to substitute the connection code for that instead, and cleanse the input variables differently.

I also used an include to execute the connection to the DB. You can ignore that if you want to and place the connection code in the same page.

Other than that, the code works. I did test it before submitting it, so I know there are no strange syntax errors.

If you have any errors, id would be helpful if you posted them here so we cab know what's going on.




----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I use 2 php files:
1. REG_FORM.php
->It has the form.
2. Insert.php
-> I use that file to connect the form to MySQL.

-----------

1st file:

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
<html>
<body>
<!-- THE FORM -->

<form method="post" action="insert.php" OnSubmit="validate(this);">

<p style="text-decoration:none;
position: absolute; left: 320px;
top: 287px; font-size: 0.9em;
font-weight: bold; color: #003300;
font-family: verdana">
Username: <input style="position: absolute;
width: 180px;" name="Username" type="text"/></p>

<p style="text-decoration:none;
position: absolute; left: 251px;
top: 312px; font-size: 0.9em;
font-weight: bold; color: #003300;
font-family: verdana">
Create a password: <input style="position: absolute;
width: 180px;" name="Password" type="password"/></p>

<p style="text-decoration:none;
position: absolute; left: 262px;
top: 337px; font-size: 0.9em;
font-weight: bold; color: #003300;
font-family: verdana">
Retype password: <input style="position: absolute;
width: 180px;" name="C_Password" type="password"/></p>

<p style="text-decoration:none;
position: absolute; left: 283px;
top: 362px; font-size: 0.9em;
font-weight: bold; color: #003300;
font-family: verdana">
E-mail address: <input style="position: absolute;
width: 180px;" name="Email" type="text"/></p>

<p style="text-decoration:none;
position: absolute; left: 217px;
top: 387px; font-size: 0.9em;
font-weight: bold; color: #003300;
font-family: verdana">
Confirm e-mail address: <input style="position: absolute;
width: 180px;" name="C_Email" type="text"/></p>


<p style="text-decoration:none;
position: absolute; left: 262px;
top: 412px; font-size: 0.9em;
font-weight: bold; color: #003300;
font-family: verdana">
Security question: <select name="S_Question"
style="position: absolute; width: 186px;">
<option value="" selected="selected">Select One</option>
<option value="Mother's birthplace">Mother's birthplace</option>
<option value="Best childhood friend">Best childhood friend</option>
<option value="Name of first pet">Name of first pet</option>
<option value="Favourite teacher">Favourite teacher</option>
<option value="Grandfather's occupation">Grandfather's occupation</option>
<option value="Other">Other</option>
</select>


<p style="text-decoration:none;
position: absolute; left: 286px;
top: 437px; font-size: 0.9em;
font-weight: bold; color: #003300;
font-family: verdana">
Secret answer: <input style="position: absolute;
width: 180px;" name="S_Answer" type="text"/></p>


<p style="text-decoration:none;
position: absolute; left: 323px;
top: 522px; font-size: 0.9em;
font-weight: bold; color: #003300;
font-family: verdana">
Nickname: <input style="position: absolute;
width: 180px;"name="Nickname" type="text"/></p>

<p style="text-decoration:none;
position: absolute; left: 316px;
top: 547px; font-size: 0.9em;
font-weight: bold; color: #003300;
font-family: verdana">
First name: <input style="position: absolute;
width: 180px;" name="F_Name" type="text"/></p>

<p style="text-decoration:none;
position: absolute; left: 318px;
top: 572px; font-size: 0.9em;
font-weight: bold; color: #003300;
font-family: verdana">
Last name: <input style="position: absolute;
width: 180px;" name="L_Name" type="text"/></p>

<p style="text-decoration:none;
position: absolute; left: 274px;
top: 597px; font-size: 0.9em;
font-weight: bold; color: #003300;
font-family: verdana">
Country/region: <select name="Country" style="position: absolute;
width: 186px;">
<option value="" selected="selected">Select Country</option>
<option value="Afghanistan">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="Antarctica">Antarctica</option>
<option value="Antigua and Barbuda">Antigua and 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="Bosnia and Herzegovina">Bosnia and Herzegovina</option>
<option value="Botswana">Botswana</option>
<option value="Brazil">Brazil</option>
<option value="British Virgin Islands">British Virgin Islands</option>
<option value="Brunei Darussalam">Brunei Darussalam</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="Cape Verde Islands">Cape Verde Islands</option>
<option value="Cayman Islands">Cayman Islands</option>
<option value="Central African Republic">Central African Republic</option>
<option value="Chad">Chad</option>
<option value="Chile">Chile</option>
<option value="China">China PR</option>
<option value="Chinese Taipei">Chinese Taipei</option>
<option value="Colombia">Colombia</option>
<option value="Comoros">Comoros</option>
<option value="Congo">Congo</option>
<option value="Congo DR">Congo DR</option>
<option value="Cook Islands">Cook Islands</option>
<option value="Costa Rica">Costa Rica</option>
<option value="Cote D'Ivoire">Cote D'Ivoire</option>
<option value="Croatia">Croatia</option>
<option value="Cuba">Cuba</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="Ecuador">Ecuador</option>
<option value="Egypt">Egypt</option>
<option value="El Salvador">El Salvador</option>
<option value="England">England</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="Faroe Islands">Faroe Islands</option>
<option value="Fiji">Fiji</option>
<option value="Finland">Finland</option>
<option value="France">France</option>
<option value="FYR Macedonia">FYR Macedonia</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="Greece">Greece</option>
<option value="Grenada">Grenada</option>
<option value="Guam">Guam</option>
<option value="Guatemala">Guatemala</option>
<option value="Guinea">Guinea</option>
<option value="Guinea-bissau">Guinea-bissau</option>
<option value="Guyana">Guyana</option>
<option value="Haiti">Haiti</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 Republic">Ireland Republic</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 DPR">Korea DPR</option>
<option value="Korea Republic">Korea Republic</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="Madagascar">Madagascar</option>
<option value="Malawi">Malawi</option>
<option value="Malaysia">Malaysia</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="Mauritania">Mauritania</option>
<option value="Mauritius">Mauritius</option>
<option value="Mexico">Mexico</option>
<option value="Micronesia">Micronesia</option>
<option value="Moldova">Moldova</option>
<option value="Mongolia">Mongolia</option>
<option value="Montenegro">Montenegro</option>
<option value="Montserrat">Montserrat</option>
<option value="Morocco">Morocco</option>
<option value="Mozambique">Mozambique</option>
<option value="Myanmar">Myanmar</option>
<option value="Namibia">Namibia</option>
<option value="Nauru">Nauru</option>
<option value="Nepal">Nepal</option>
<option value="Netherlands">Netherlands</option>
<option value="Netherlands Antilles">Netherlands Antilles</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="Northern Mariana Islands">Northern Mariana Islands</option>
<option value="Northern Ireland">Northern Ireland</option>
<option value="Norway">Norway</option>
<option value="Oman">Oman</option>
<option value="Pakistan">Pakistan</option>
<option value="Oman">Palestine</option>
<option value="Palau">Palau</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="Philippines">Philippines</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="Romania">Romania</option>
<option value="Russia">Russia</option>
<option value="Rwanda">Rwanda</option>
<option value="Samoa">Samoa</option>
<option value="San Marino">San Marino</option>
<option value="Sao Tome e Principe">Sao Tome e Principe</option>
<option value="Saudi Arabia">Saudi Arabia</option>
<option value="Scotland">Scotland</option>
<option value="Senegal">Senegal</option>
<option value="Serbia">Serbia</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="Sri Lanka">St. Kitts and Nevis</option>
<option value="Sri Lanka">St. Lucia</option>
<option value="Sri Lanka">St. Vincent/Grenadines</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="Tajikistan">Tajikistan</option>
<option value="Tanzania">Tanzania</option>
<option value="Thailand">Thailand</option>
<option value="Timor-leste">Timor-leste</option>
<option value="Togo">Togo</option>
<option value="Tonga">Tonga</option>
<option value="Trinidad and Tobago">Trinidad and Tobago</option>
<option value="Tunisia">Tunisia</option>
<option value="Turkey">Turkey</option>
<option value="Turkmenistan">Turkmenistan</option>
<option value="Turks and Caicos Islands">Turks and Caicos Islands</option>
<option value="Uganda">Uganda</option>
<option value="Ukraine">Ukraine</option>
<option value="United Arab Emirates">United Arab Emirates</option>
<option value="Uruguay">Uruguay</option>
<option value="US Virgin Islands">US Virgin Islands</option>
<option value="USA">USA</option>
<option value="Uzbekistan">Uzbekistan</option>
<option value="Vanuatu">Vanuatu</option>
<option value="Venezuela">Venezuela</option>
<option value="Vietnam">Vietnam</option>
<option value="Wales">Wales</option>
<option value="Yemen">Yemen</option>
<option value="Zambia">Zambia</option>
<option value="Zimbabwe">Zimbabwe</option>
</select>



<p style="text-decoration:none;
position: absolute; left: 367px;
top: 622px; font-size: 0.9em;
font-weight: bold; color: #003300;
font-family: verdana">
City: <input style="position: absolute;
width: 180px;" name="City" type="text"/></p>

<p style="text-decoration:none;
position: absolute; left: 341px;
top: 647px; font-size: 0.9em;
font-weight: bold; color: #003300;
font-family: verdana">
Gender: <input type="radio" name="Gender"
value="Male">Male</input>
<input type="radio" name="Gender"
value="Female">Female</input></p>


<p style="text-decoration:none;
position: absolute; left: 320px;
top: 672px; font-size: 0.9em;
font-weight: bold; color: #003300;
font-family: verdana">
Birth date: <select name="DoB_Day">
<option> - Day - </option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>


<select name="DoB_Month">
<option> - Month - </option>
<option value="January">January</option>
<option value="Febuary">Febuary</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select>



<select name="DoB_Year">
<option> - Year - </option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
<option value="2002">2002</option>
<option value="2001">2001</option>
<option value="2000">2000</option>
<option value="1999">1999</option>
<option value="1998">1998</option>
<option value="1997">1997</option>
<option value="1996">1996</option>
<option value="1995">1995</option>
<option value="1994">1994</option>
<option value="1993">1993</option>
<option value="1992">1992</option>
<option value="1991">1991</option>
<option value="1990">1990</option>
<option value="1989">1989</option>
<option value="1988">1988</option>
<option value="1987">1987</option>
<option value="1986">1986</option>
<option value="1985">1985</option>
<option value="1984">1984</option>
<option value="1983">1983</option>
<option value="1982">1982</option>
<option value="1981">1981</option>
<option value="1980">1980</option>
<option value="1979">1979</option>
<option value="1978">1978</option>
<option value="1977">1977</option>
<option value="1976">1976</option>
<option value="1975">1975</option>
<option value="1974">1974</option>
<option value="1973">1973</option>
<option value="1972">1972</option>
<option value="1971">1971</option>
<option value="1970">1970</option>
<option value="1969">1969</option>
<option value="1968">1968</option>
<option value="1967">1967</option>
<option value="1966">1966</option>
<option value="1965">1965</option>
<option value="1964">1964</option>
<option value="1963">1963</option>
<option value="1962">1962</option>
<option value="1961">1961</option>
<option value="1960">1960</option>
<option value="1959">1959</option>
<option value="1958">1958</option>
<option value="1957">1957</option>
<option value="1956">1956</option>
<option value="1955">1955</option>
<option value="1954">1954</option>
<option value="1953">1953</option>
<option value="1952">1952</option>
<option value="1951">1951</option>
<option value="1950">1950</option>
<option value="1949">1949</option>
<option value="1948">1948</option>
<option value="1947">1947</option>
<option value="1946">1946</option>
<option value="1945">1945</option>
<option value="1944">1944</option>
<option value="1943">1943</option>
<option value="1942">1942</option>
<option value="1941">1941</option>
<option value="1940">1940</option>
<option value="1939">1939</option>
<option value="1938">1938</option>
<option value="1937">1937</option>
<option value="1936">1936</option>
<option value="1935">1935</option>
<option value="1934">1934</option>
<option value="1933">1933</option>
<option value="1932">1932</option>
<option value="1931">1931</option>
<option value="1930">1930</option>
<option value="1929">1929</option>
<option value="1928">1928</option>
<option value="1927">1927</option>
<option value="1926">1926</option>
<option value="1925">1925</option>
<option value="1924">1924</option>
<option value="1923">1923</option>
<option value="1922">1922</option>
<option value="1921">1921</option>
<option value="1920">1920</option>
<option value="1919">1919</option>
<option value="1918">1918</option>
<option value="1917">1917</option>
<option value="1916">1916</option>
<option value="1915">1915</option>
<option value="1914">1914</option>
<option value="1913">1913</option>
<option value="1912">1912</option>
<option value="1911">1911</option>
<option value="1910">1910</option>
<option value="1909">1909</option>
<option value="1908">1908</option>
<option value="1907">1907</option>
<option value="1906">1906</option>
<option value="1905">1905</option>
<option value="1904">1904</option>
<option value="1903">1903</option>
<option value="1902">1902</option>
<option value="1901">1901</option>
<option value="1900">1900</option>
</select></p>

<p style="text-decoration:none;
position: absolute; left: 366px;
top: 757px; font-size: 0.9em;
font-weight: bold; color: #003300;
font-family: verdana">
ICQ: <input style="position: absolute;
width: 180px;" name="ICQ" type="text"/></p>

<p style="text-decoration:none;
position: absolute; left: 363px;
top: 782px; font-size: 0.9em;
font-weight: bold; color: #003300;
font-family: verdana">
MSN: <input style="position: absolute;
width: 180px;" name="MSN" type="text"/></p>

<p style="text-decoration:none;
position: absolute; left: 259px;
top: 807px; font-size: 0.9em;
font-weight: bold; color: #003300;
font-family: verdana">
Yahoo messenger: <input style="position: absolute;
width: 180px;" name="YAHOO" type="text"/></p>

<p style="text-decoration:none;
position: absolute; left: 340px;
top: 950px;">
<input type="submit" name="action"
value="Create Account" />
</p>




</form>



</body>
</html>
 
2nd File

<?php
$con = mysql_connect("localhost","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("Accounts", $con);

$sql="INSERT INTO RG_Private_Data (Username, Password, C_Password,
Email, C_Email, S_Question, S_Answer, Nickname, F_Name,
L_Name, Country, City, Gender, DoB_Day, DoB_Month,
DoB_Year, ICQ, MSN, YAHOO)
VALUES
('$_POST[Username]','$_POST[Password]','$_POST[C_Password]'
,'$_POST','$_POST[C_Email]','$_POST[S_Question]'
,'$_POST[S_Answer]'
,'$_POST[Nickname]','$_POST[F_Name]','$_POST[L_Name]'
,'$_POST[Country]','$_POST[City]','$_POST[Gender]'
,'$_POST[DoB_Day]','$_POST[DoB_Month]','$_POST[DoB_Year]'
,'$_POST[ICQ]','$_POST[MSN]','$_POST[YAHOO]')";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";

mysql_close($con)
?>
 
Well, Good news...I moved one step forward...Now It validates that the user didn't leave the Username field blank.


I used 4 files:
1. the form.php
2. insert.php
3. validate.js
4. formvalidation.php
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top