By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,503 Members | 1,143 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,503 IT Pros & Developers. It's quick & easy.

validation in JavaScript

P: 1
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
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
"is not working" is not an error description. what does the code do it shouldn’t (or vice versa)?
Apr 19 '12 #2

Post your reply

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