Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在html页面中找不到验证_Php_Html_Mysql - Fatal编程技术网

Php 在html页面中找不到验证

Php 在html页面中找不到验证,php,html,mysql,Php,Html,Mysql,<head> <title> Add User page</title> <link href="css/style.css" rel="stylesheet" type="text/css" /> <form name='f2' action="insert_ac.php" method="post" > <script src="validation.js" type="javascript/text"></scr

<head>
<title> Add User page</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<form name='f2' action="insert_ac.php" method="post" >
<script src="validation.js" type="javascript/text"></script> 
</head>
<body  onload="firstfocus();">
<table align="center" border="0" cellpadding="3" cellspacing="1">
 <tr>
 <td> First Name</td><td > : </td>
 <td>  <input type='text' name='fname' id='fid' size="50" style="background-color:#abcddd; height:18px;" value='' maxlength="100" onblur="fname_validation(5,12);">    </td>
  </tr>
 <tr>
<td> Last Name</td><td> : </td>
 <td> <input type='text' name='lname' id='lid' size="50" style="background-color:#abcddd; height:18px; "value='' maxlength="100" onblur="lname_validation(5,12);"> </td>
  </tr>
 <tr>
<td> Gender</td><td> : </td>
<td> <input type='radio' name='gend' id='m' value='M' checked>Male <input type='radio' name='gend' id='f' value='F'>Female</td>
</tr>
<tr>
<td> Phone Number</td><td> : </td>
 <td> <input type='number_format' name='phone' id='phno'size="50" style="background-color:#abcddd; height:18px; " value=''onblur="allnumeric();"></td>
 </tr>
  <tr>
  <td> Work Experiance</td><td> : </td>
   <td><select name="exp" onblur="expselect();">
   <option > Select One</option>
   <option selected="" value="Default"> Select One </option>
   <option value="F"> Fresher </option>
   <option value="E"> Experiance</option>
   </select></td>
   </tr>
   <tr>
   <td>User Name</td><td>:</td><td> <input type='txt' name='uname' id='uid'size="50" style="background-color:#abcddd; height:18px; " value=''onblur="userid_validation(5,10);">   </td>
   </tr>
    <tr>
   <td>Password</td><td>:</td><td> <input type='password' name='pwd' id='pid' size="50" style="background-color:#abcddd; height:18px; " value=''onblur="passid_validation(7,12);"></td>
   </tr>
  <tr>
 <td>&nbsp;</td>
  <td>&nbsp;</td>
 <td width="84"><input name="enter" class="btn_login" type="submit" value="Submit"  onsubmit="alert('Data stored successfully');"/>&nbsp;&nbsp;<input name="cancle" class="btn_login" type="reset" value="Cancle" /></td>
  </tr>
 </table>

 </form>
 </body>
 </html>

添加用户页面
名字:
姓氏:
性别:
男女
电话号码:
工作经验:
选择一个
选择一个
新鲜的
经验
用户名:
密码:
我使用script标记包含了外部javascript文件,但验证不起作用

<head>
<title> Add User page</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<form name='f2' action="insert_ac.php" method="post" >
<script src="validation.js" type="javascript/text"></script> 
</head>
<body  onload="firstfocus();">
<table align="center" border="0" cellpadding="3" cellspacing="1">
 <tr>
 <td> First Name</td><td > : </td>
 <td>  <input type='text' name='fname' id='fid' size="50" style="background-color:#abcddd; height:18px;" value='' maxlength="100" onblur="fname_validation(5,12);">    </td>
  </tr>
 <tr>
<td> Last Name</td><td> : </td>
 <td> <input type='text' name='lname' id='lid' size="50" style="background-color:#abcddd; height:18px; "value='' maxlength="100" onblur="lname_validation(5,12);"> </td>
  </tr>
 <tr>
<td> Gender</td><td> : </td>
<td> <input type='radio' name='gend' id='m' value='M' checked>Male <input type='radio' name='gend' id='f' value='F'>Female</td>
</tr>
<tr>
<td> Phone Number</td><td> : </td>
 <td> <input type='number_format' name='phone' id='phno'size="50" style="background-color:#abcddd; height:18px; " value=''onblur="allnumeric();"></td>
 </tr>
  <tr>
  <td> Work Experiance</td><td> : </td>
   <td><select name="exp" onblur="expselect();">
   <option > Select One</option>
   <option selected="" value="Default"> Select One </option>
   <option value="F"> Fresher </option>
   <option value="E"> Experiance</option>
   </select></td>
   </tr>
   <tr>
   <td>User Name</td><td>:</td><td> <input type='txt' name='uname' id='uid'size="50" style="background-color:#abcddd; height:18px; " value=''onblur="userid_validation(5,10);">   </td>
   </tr>
    <tr>
   <td>Password</td><td>:</td><td> <input type='password' name='pwd' id='pid' size="50" style="background-color:#abcddd; height:18px; " value=''onblur="passid_validation(7,12);"></td>
   </tr>
  <tr>
 <td>&nbsp;</td>
  <td>&nbsp;</td>
 <td width="84"><input name="enter" class="btn_login" type="submit" value="Submit"  onsubmit="alert('Data stored successfully');"/>&nbsp;&nbsp;<input name="cancle" class="btn_login" type="reset" value="Cancle" /></td>
  </tr>
 </table>

 </form>
 </body>
 </html>
这是我的外部javascript代码,保存为validation.js,我找不到其中的错误,请帮助我

// After form loads focus will go to first name field.  
function firstfocus()  
{  
var fname = document.f2.fname.focus();  
return true;  
}  
// This function will validate First name  
function fname_validation(mx,my)  
{  
var fname = document.f2.fname;  
var fname_len = fname.value.length; 
var letters = /^[A-Za-z]+$/;  
 if (fname_len == 0 || fname_len >= my || fname_len < mx)  
{  
alert("First Name should not be empty / length be between "+mx+" to "+my);  
fname.focus();  
return false;  
      if(fname.value.match(letters)) 
    {  
// Focus goes to next field i.e.Last Name  
 document.f2.lname.focus();  
return true;  
 }  
}  
 }

 // This function will validate Last name  
function lname_validation(mx,my)  
 {  
 var lname = document.f2.lname;  
 var lname_len = lname.value.length; 
 var letters = /^[A-Za-z]+$/;    
 if (lname_len == 0 || lname_len >= my || lname_len < mx)  
 {  
  alert("Last Name should not be empty / length be between "+mx+" to "+my);  
  lname.focus();  
    return false;  
    if(fname.value.match(letters)) 
    {  
    // Focus goes to next field i.e.Phone Number  
     document.f2.phone.focus();  
   return true;  
   }  
   }  
   }

  // This function will validate Phone Number.  
  function allnumeric()  
   {   
   var phone = document.f2.phone;  
     var numbers = /^[0-9]+$/;  
     if(phone.value.match(numbers))  
     {  
    // Focus goes to next field i.e. Experiance.  
   document.f2.exp.focus();  
    return true;  
   }  
   else  
   {  
   alert('Phone Number must have numeric characters only');  
   phone.focus();  
   return false;  
   }  
   }    
   // This function will select Experiance.  
    function expselect()  
    {  
   var exp = document.f2.exp;  
   if(exp.value == "Default")  
   {  
   alert('Select your Experiance from the list');  
   exp.focus();  
   return false;  
   }  
   else  
   {  
   // Focus goes to next field i.e. Username Code.  
   document.f2.uname.focus();  
   return true;  
  }  
  }  

  // This function will validate User Name.  
  function allLetter()  
   {   
   var uname = document.f2.uname;  
   var letters = /^[A-Za-z]+$/;  
  if(uname.value.match(letters))  
   {  
   // Focus goes to next field i.e. Password.  
    document.f2.pwd.focus();  
     return true;  
    }  
    else  
     {  
     alert('Username must have alphabet characters only');  
    uname.focus();  
     return false;  
     }  
     }  

    // This function will validate Password.  
   function passid_validation(mx,my)  
   {  
   var passid = document.registration.passid;  
    var passid_len = passid.value.length;  
   if (passid_len == 0 ||passid_len >= my || passid_len < mx)  
    {  
    alert("Password should not be empty / length be between "+mx+" to "+my);  
     passid.focus();  
     return false;  
     }  
     }  
//加载表单后,焦点将转到“名字”字段。
函数firstfocus()
{  
var fname=document.f2.fname.focus();
返回true;
}  
//此函数将验证名字
函数fname_验证(mx,my)
{  
var fname=document.f2.fname;
var fname_len=fname.value.length;
变量字母=/^[A-Za-z]+$/;
如果(fname|u len==0 | | fname|len>=my | | fname|len=my | | lname|len=my | passid_ulen
如果.js与html不在同一文件夹中,则必须引用它

编辑
函数fname\u验证(mx,my)
{

缺少结束括号!

尝试将
更改为

并仔细检查js文件的引用。另外,进行警报检查以确定它是否真的通过了firstFocus()函数。

我更改了java脚本文件,现在可以在表单中找到验证

谢谢你的帮助

在这里我分享我的代码

HTML代码

   <form name='f1' action="insert_ac.php" method="post" onSubmit="return validateForm();" >
     <tr>
   <td height="25" height="25" colspan="2" bgcolor="#EC6921" class="form_heading">Add User Form</td>
</tr>
                     <tr>
                    <td bgcolor="#FFFFFF"   height="28" class="form_txt"> First Name:</td> 
                    <td bgcolor="#FFFFFF">  <input type='text' name='fname' id='fid' size="50" style="height:18px;" value='' maxlength="100" ></td>
                </tr>
                <tr>
                    <td bgcolor="#FFFFFF" height="28" class="form_txt"> Last Name:</td>
                    <td bgcolor="#FFFFFF" > <input type='text' name='lname' id='lid' size="50" style=" height:18px; "value='' maxlength="100" ></td>
                </tr>
                <tr>
                    <td bgcolor="#FFFFFF" height="28" class="form_txt"> Gender:</td>
                    <td bgcolor="#FFFFFF" > <input type='radio' name='gend' id='m' value='M' checked>Male <input type='radio' name='gend' id='f' value='F'>Female</td>
                </tr>
                <tr>
                    <td bgcolor="#FFFFFF" height="28" class="form_txt"> Phone Number:</td>
                    <td bgcolor="#FFFFFF" > <input type='number_format' name='phone' id='phno'size="50" style=" height:18px; " value=''></td>
                </tr>
                <tr>
                    <td bgcolor="#FFFFFF" height="28" class="form_txt"> Work Experiance:</td>
                    <td bgcolor="#FFFFFF" ><select name="exp" >
                            <option selected="" value="Default"> Select One </option>
                            <option value="Fresher"> Fresher </option>
                            <option value="Experiance"> Experiance</option>
                        </select></td>
                </tr>
                <tr>
                    <td bgcolor="#FFFFFF" height="28" class="form_txt">User Name:</td><td bgcolor="#FFFFFF"> <input type='txt' name='uname' id='uid'size="50" style=" height:18px; " value=''></td>
                </tr>
                <tr>
                    <td bgcolor="#FFFFFF" height="28" class="form_txt">Password:</td><td bgcolor="#FFFFFF"> <input type='password' name='pwd' id='pid' size="50" style=" height:18px; " value=''></td>
                </tr>
                     </table>
        <table align="center">
                <tr>
                  <td ><input name="enter" class="btn_login" type="submit" value="Submit" align="center"><input name="cancle" class="btn_login" type="reset" value="Cancle" valign="right" /></td>
                </tr>
   </table>
        </div>
      </div>
    </div>
   </form>


   </body>
  </html> 

添加用户表单
名字:
姓氏:
性别:
男女
电话号码:
工作经验:
选择一个
新鲜的
经验
用户名:
密码:
这是我的java脚本文件,运行良好

   var RE = /^.+@.+\..{3}$/;
   var RE1 = /^[a-zA-Z]+$/;
    var RE2 = /^[0-9]{10}$/;
     var RE3 = /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/;
    function validateForm()
    {
      if (document.f1.fname.value == "")
      {
    window.alert("first name should NOT BE empty");
    document.f1.fname.focus();
    return false;
   }
   else
    if (RE1.test(document.f1.fname.value) == false)
    {
      alert("Invalid first name\n\
      ");
       return false;
     }
     else
    if (document.f1.fname.value.length < 3)
     {
    window.alert("Firstname must have atleast Three characters");
    document.f1.fname.focus();
    return false;
    }
     else
     if (document.f1.lname.value == "")
    {
    window.alert("Lastname should not be empty");
    document.f1.lname.focus();
    return false;
     }
    else
   if (RE1.test(document.f1.lname.value) == false)
    {
    alert("Invalid last name");
    return false;
    }
    else
     if (document.f1.lname.value.length < 4)
     {
    window.alert("Lastname must have atleast four characters");
    document.f1.lname.focus();
    return false;
     }
     else
     if (document.f1.lname.value == "")
    {
    window.alert("Last name should not be empty");
    document.f1.lname.focus();
    return false;
      }
    else
     if (document.f1.phone.value == "")
     {
    window.alert("phne no should NOT BE empty");
    document.f1.phone.focus();
    return false;
     } else
     if (RE3.test(document.f1.phone.value) == false)
     {
    alert("Invalid phone number");
    document.f1.phone.focus();
    return false;
     }
     else
     if (document.f1.exp.selectedIndex == 0)
     {
        window.alert("please select work experiance ");
       return false;
     }
     else
      if (document.f1.uname.value == "")
    {
    window.alert("UserName should not be empty");
    document.f1.uname.focus();
    return false;
    }
    else
    if (RE1.test(document.f1.uname.value) == false)
    {
    window.alert("Invalid userName ");
    document.f1.uname.focus();
    return false;
    }

    else
    if (document.f1.pwd.value == "")
    {
    window.alert("password should not be empty");
    document.f1.pwd.focus();
    return false;
     }
    else
   if (document.f1.pwd.value.length < 6)
    {
    window.alert("password must have atleast six characters");
    document.f1.pwd.focus();
    return false;
     }

    else
    {
    window.alert("User has been added successfully.");
    return true;
     }
     }
var RE=/^.+@.+\..{3}$/;
变量RE1=/^[a-zA-Z]+$/;
var RE2=/^[0-9]{10}$/;
变量RE3=/^\(?(\d{3})\)?[-](\d{3})[-]?(\d{4})$/;
函数validateForm()
{
如果(document.f1.fname.value==“”)
{
window.alert(“名字不应为空”);
document.f1.fname.focus();
返回false;
}
其他的
if(RE1.test(document.f1.fname.value)==false)
{
警报(“无效的名字\n”\
");
返回false;
}
其他的
if(document.f1.fname.value.length<3)
{
window.alert(“名字必须至少有三个字符”);
document.f1.fname.focus();
返回false;
}
其他的
如果(document.f1.lname.value==“”)
{
window.alert(“Lastname不应为空”);
document.f1.lname.focus();
返回false;
}
其他的
if(RE1.test(document.f1.lname.value)==false)
{
警告(“无效姓氏”);
返回false;
}
其他的
if(document.f1.lname.value.length<4)
{
窗口警报(“Las