473,396 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

validation in JavaScript

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. include ("connection.php");
  4. if (isset($_POST["register"]))
  5. {
  6.     $name=$_POST['name'];
  7.     $username=$_POST['username'];
  8.     $password=md5($_POST['pwd']);
  9.     $email=$_POST['email'];
  10.     $gender=$_POST['sex'];
  11.     $address=$_POST['area'];
  12.     $religion=$_POST['list'];
  13.     $image=$_FILES['file']['name'];
  14.  
  15.  
  16.     $a=explode('.',$image);
  17.     $b=$a[1];
  18.     $str=$b;
  19.     $str=strtolower($str);
  20.     if($str == 'pjpeg'|| $str == 'jpeg' || $str == 'x-png' || $str == 'png' || $str == 'gif' || $str == 'jpg')
  21.     {
  22.         $i=$user_no.time().'.'.$str;
  23.         move_uploaded_file($_FILES['file']['tmp_name'],"pictures/".$i);
  24.         include("resize.php");
  25.         $sql=mysql_query("SELECT *FROM `login` WHERE `user_id`='$username'");
  26.         $count=mysql_fetch_row($sql);
  27.  
  28.         if($count!=0)
  29.         {
  30.             $err_msg="username already exist!";
  31.         }
  32.         else
  33.         {
  34.              mysql_query("INSERT INTO login(user_name,user_id,user_pwd,user_email,user_gender,user_addrs,user_reli,user_image) VALUES('$name','$username','$password','$email','$gender','$address','$religion','$i')")or die(mysql_error());
  35.             $row=mysql_insert_id(); 
  36.             $_SESSION['id']=$row;
  37.             header("location:profile.php");
  38.         }
  39.     }
  40.  
  41. }
  42. ?>    
  43.  
  44.  
  45. <head>
  46. <script language="javascript" type="text/javascript">
  47.     function valid()
  48.     {
  49.         clear();
  50.         if(document.getElementById('name').value=='')
  51.         {
  52.             document.getElementById('error_name').style.display="block";
  53.             document.getElementById('name').focus();
  54.             return false;
  55.         }
  56.         else if(document.getElementById('username').value=='')
  57.         {
  58.             document.getElementById('error_username').style.display="block";
  59.             document.getElementById('username').focus();
  60.             return false;
  61.         }
  62.         else if(document.getElementById('password').value=='')
  63.         {
  64.             document.getElementById('error_password').style.display="block";
  65.             document.getElementById('password').focus();
  66.             return false;
  67.         }
  68.         else if(document.getElementById('passwrd').value=='')
  69.         {
  70.             document.getElementById('error_passwrd').style.display="block";
  71.             document.getElementById('passwrd').focus();
  72.             return false;
  73.         }
  74.         else if(document.getElementById('password').value!=document.getElementById('passwrd').value)
  75.         {
  76.             document.getElementById('error_mismatch').style.display="block";
  77.             document.getElementById('passwrd').focus();
  78.             return false;
  79.         }
  80.  
  81.         else if(document.getElementById('mail').value=='')
  82.         {
  83.             document.getElementById('error_mail').style.display="block";
  84.             document.getElementById('mail').focus();
  85.             return false;
  86.         }
  87.         else if(((document.getElementById('mail').value.length)<4) || ((document.getElementById('mail').value.length)>40))
  88.         {
  89.             document.getElementById('error_email').style.display="block";
  90.             document.getElementById('mail').focus();
  91.             return false;
  92.         }
  93.         else if((document.getElementById('mail').value.indexOf("@")<1)||(document.getElementById('mail').value.indexOf(".")<1))
  94.         {
  95.             document.getElementById('error_email').style.display="block";
  96.             document.getElementById('mail').focus();
  97.             return false;
  98.         }
  99.  
  100.         else if(document.getElementById('religion').value=='c1')
  101.         {
  102.  
  103.             document.getElementById('error_reli').style.display="block";
  104.             document.getElementById('religion').focus();
  105.             return false;
  106.         }
  107.         else if(document.getElementById('file').value=="")
  108.         {
  109.             document.getElementById('error_image').style.display="block";
  110.             document.getElementById('file').focus();
  111.             return false;
  112.         }
  113.         else
  114.         {
  115.             return true;
  116.         }
  117.     }
  118. function clear()
  119. {
  120.     document.getElementById('error_name').style.display="none";
  121.     document.getElementById('error_username').style.display="none";
  122.     document.getElementById('error_password').style.display="none";
  123.     document.getElementById('error_passwrd').style.display="none";
  124.     document.getElementById('error_mismatch').style.display="none";
  125.     document.getElementById('error_mail').style.display="none";
  126.     document.getElementById('error_email').style.display="none";
  127.     document.getElementById('error_reli').style.display="none";
  128.     document.getElementById('error_image').style.display="none";
  129. }
  130. </script>
  131. </head>
  132.  
  133.  
  134. <html>
  135. <body style="background-color:#F3E2A9">    
  136.     <form name="FORM" method="post" action="<?=$_SERVER['PHP_SELF']?>"   enctype="multipart/form-data"                 onSubmit="return valid();"> 
  137.         <center>    
  138.             <h1 style="color:green"><b>PROFILE<b></h1>
  139.                 <table style=margin-top:30px bgcolor="#FFFFCC" width="450" cellspacing="10"                                   cellpadding="5" >
  140.                       <tr>
  141.                         <td>*Name</td>
  142.                         <td><input type="text" name="name" id="name" size="20" value="<? echo $name?>"                        /></td>
  143.                         <td><div style="display:none; color:#CC0000" id="error_name"><i><b>
  144.                             enter name</b></i></div></td>
  145.                       </tr>
  146.                       <tr>
  147.                         <td>*username</td>
  148.                         <td><input type="text" name="username" id="username" siz="20" value="<? echo                        $username?>"/></td>
  149.                         <td><div style="display:none; color:#CC0000" id="error_username"><i><b>
  150.                             enter username</b></i></div></td>
  151.                         <td><td><span style="color:#CC0000"><i><b><?php echo $err_msg;?></b></i>
  152.                         </span></td></td>
  153.                       </tr>
  154.                       <tr>
  155.                         <td>*password</td>
  156.                         <td><input type="password" name="pwd" id="password" size="20"/></td>
  157.                         <td><div style="display:none; color:#CC0000" id="error_password"><i><b>
  158.                             enter password</b></i></div></td>
  159.                       </tr>
  160.                       <tr>
  161.                            <td>*retype password</td>
  162.                         <td><input type="password" name="pswd" id="passwrd" size="20"/></td>
  163.                         <td><div style="display:none; color:#CC0000" id="error_passwrd"><i><b>
  164.                             retype your password</b></i></div></td>
  165.                         <td><td><div style="display:none; color:#CC0000" id="error_mismatch"><i><b>
  166.                             password not matched</b></i></div></td></td>
  167.                       </tr>
  168.                       <tr>
  169.                         <td>*E-mail</td>
  170.                         <td><input type="text" name="email" id="mail" size="20" value="<? echo $email                                                    ?>"/>
  171.                         </td>
  172.                         <td><div style="display:none; color:#CC0000" id="error_mail"><i><b>
  173.                             enter email</b></i></div></td>
  174.                         <td><div style="display:none; color:#CC0000" id="error_email"><i><b>
  175.                             invalid email</b></i></div></td>
  176.                       </tr>
  177.                     <tr>
  178.                         <td>*Gender</td>
  179.                         <td><input type="radio" name="sex" value="female" id="sex" <? if($gender==                            "female") 
  180.                            {?> checked="checked" <? } ?>/>Female
  181.                             <input type="radio" name="sex" value="male" id="sex"/ <? if($gender==                            "male") 
  182.                             {?> checked="checked" <? } ?>checked="checked"/>Male
  183.                         </td>
  184.                     </tr>
  185.                     <tr>
  186.                         <td>Address</td>
  187.                         <td><textarea name="area" rows="10" id="addrs"><? echo $address;?></textarea>
  188.                         </td>
  189.                     </tr>
  190.                     <tr>
  191.                     <tr>
  192.                         <td>*Religion</td>
  193.                         <td><select name="list" onChange="formValues=('FORM','list')">
  194.                         <option value="c1" id="religion">--SELECT--</option>
  195.                         <option value="c2" id="religion">christian</option>
  196.                         <option value="c3" id="religion">hindu</option>
  197.                         <option value="c4" id="religion">muslim</option>
  198.                         <option value="c5" id="religion">other</option>
  199.                         </select></td>
  200.                         <td><div style="display:none; color:#CC0000" id="error_reli"><i><b>
  201.                         select religion</b></i></div></td>
  202.                     </tr>
  203.  
  204.  
  205.                     <tr>
  206.                         <td>*Profile Image</td>
  207.                         <td><input type="file" name="file" id="file" value="<? echo $i; ?>"/></td>
  208.                         <td><div style="display:none; color:#CC0000" id="error_image"><i><b>
  209.                             choose image</b></i></div></td>
  210.  
  211.                     </tr>
  212.  
  213.  
  214.                 </table>
  215.                 <input type="reset" name="clear" value="clear"/>
  216.                 <input type="submit" name="register" value="register" onClick="return valid();"/>
  217.                 <a href="login.php"><b><font color="green">home</font></b></a> 
  218.  
  219.         </center>
  220.     </form>
  221. </body>
  222. </html>
  223.  
Apr 19 '12 #1
1 1881
Dormilich
8,658 Expert Mod 8TB
"is not working" is not an error description. what does the code do it shouldn’t (or vice versa)?
Apr 19 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: mhk | last post by:
Hi, Is there any way to create/set Session veriable in JavaScript. Please let me know if anyone has an idea. Thanks alot.
2
by: megabyte | last post by:
Hello; I have an ASP application which gathers information to put in a database via some forms - I would like to do the form validation (making sure some fields are not empty) with a Javascript...
2
by: Fourge | last post by:
Hi, I have run into a very strange scenario. In developing an ASP.NET application on framework version 1.1, I found that certain client-side validation scripts were not being rendered. The...
1
by: avp | last post by:
Hi, We have an ASP.NET 2.0 (C#) application that has a web form with a CheckBoxList control and a CustomValidator control. The CustomValidator control is used to validate that at least one...
0
by: Ben Fidge | last post by:
What is the correct way to determine if javascript for client-side validation has been registered in ASP.NET 2.0? I'm trying to debug a control that uses the following to detect: bool...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
0
by: IrishDudeInUSA | last post by:
Greetings, I am trying to track a fix for the asp.net 2.0 javascript validation bug where if you are using validation controls a javascript error occurs in Internet Explorer 6.0. I was wondering...
3
parshupooja
by: parshupooja | last post by:
I want to validate a date via javascript. Date should not be in future and date should not me more than seven days old. Any idea? help
9
hgeithus
by: hgeithus | last post by:
Hi. I'm doing a form at my website, and I found this document which is very interesting: Javascript form validation - doing it right . I have a little question though. All the documents within my...
2
by: whereswally007 | last post by:
Ok below is my javascript code that gets activated when the used changed the input text box it doesnt work before what im searching is wrong can someone help me please. for address i need it so that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.