CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Web 开发 >  PHP

怎样把数据库中的数据填到表单中去

楼主debussy(debussy)2001-11-20 16:00:52 在 Web 开发 / PHP 提问

      在我的表中有一个字段是地区名称,我希望在选择上级单位之后能够在页面产生一个下拉列表框,把该地区的所属下级单位从库里面取出来,然后填充到该列表框中,以便于用户直接从该框中选择。如何才能实现?谢谢 问题点数:20、回复次数:6Top

1 楼zxyufan(宇凡)回复于 2001-11-20 21:18:03 得分 20

<html>  
  <head>  
  <title>阶梯购书网|用户注册</title>  
  <meta   HTTP-EQUIV="keywords"  
  CONTENT="bookshop,bookstore,AV,bookshop,book,books,books   online,shop,online,   shop,music,movie,article,page,booktop,bestseller,publish,computer,publish,author,literature,life,bestsellers,education,economy,IT,CD,VCD,bookstore,artice,product,MP3,RAM,RA">  
  <style>  
  #h{cursor:hand;   text-indent:-20px;  
  list-style-image:url(fold.gif)}  
  #h1{cursor:hand;   text-indent:-50px;  
  list-style-image:url(fold.gif)}  
  #h2{cursor:hand;   text-indent:-75px;  
  list-style-image:url(fold.gif)}  
  #ls{text-indent:-50px;list-style-image:url(list.gif)}  
  #c2{text-indent:-50px}  
  #c3{text-indent:-75px}  
  #c4{text-indent:-100px}  
  </style>  
  <link   rel="stylesheet"   href="../style/jieti.net.css"   type="text/css">  
  <script src="../js/browsehead.js"   type="text/javascript"   language="Javascript"></script>  
  <script   language="JavaScript">  
  var   Array0   =     new   Array("('请选择所在院系','0',true,true)");  
  var   Array1   =   new   Array("('请选择所在院系','0',true,true)","('通信学院','1')","('电子工程学院','2')","('微电子科学与工程系','3')","('电子机械系','4')","('光电子技术系','5')","('外语系','6')","('电工学院','7')","('计算机科学与工程学院','8')","('管理学院','9')","('人文社科院','10')","('应用数学系','11')","('应用物理系','12')","('应用物理研究所','13')","('自动化系','14')","('信息材料工程学院','15')","('能信与信息工程学院','16')","('高能电子研究所','17')");  
  var   Array2   =   new   Array("('请选择所在院系','0',true,true)","('建筑学院','1')","('纺织与服装工程学院','2')","('电子信息学院','3')","('数学学院','4')","('管理学院','5')","('法学院','6')","('外语学院','7')","('经济学院','8')","('哲学院与艺术学院','9')","('文学与新闻学院','10')");  
  var   Array3   =   new   Array("('请选择所在院系','0',true,true)","('金融学院','1')","('保险学院','2')","('会计学院','3')","('工商管理学院','4')","('财政税务学院','5')","('经济学院','6')","('统计学系','7')","('经济信息工程系','8')","('法学系','9')","('经贸外语系','10')","('政治系','11')","('国际商学院','12')","('旅游管理学院','13')");  
  var   Array4   =   new   Array("('请选择所在院系','0',true,true)","('信息工程学院','1')","('环境与土木工程学院','2')","('艺术学院','3')","('成人教育学院','4')","('地质学系','5')","('应用化学系','6')","('石油系','7')","('核原料与核技术工程系','8')","('应用数学系','9')","('勘察与机电工程系','10')","('社会科学院系','11')","('管理科学系','12')","('资源与经济系','13')","('外语系','14')");  
  var   Array5   =   new   Array("('请选择所在院系','0',true,true)","('计算机与通信工程学院','1')","('电气工程学院','2')","('土木工程学院','3')","('环境科学与工程学院','4')","('机械工程学院','5')","('交通运输学院','6')","('经济管理学院','7')","('人文社会科学学院','8')","('建筑系','9')","('材料工程系','10')","('应用力学与工程系','11')","('应用数学系','12')","('应用物理系','13')","('外国语学院','14')","('生物工程系','15')","('旅游管理专业','16')");  
  var   Array6   =   new   Array("('请选择所在院系','0',true,true)","('文学院','1')","('外国语学院','2')","('艺术学院','3')","('教育科学学院','4')","('化学与生命科学学院','5')","('数学与软件科学学院','6')","('电子工程学院','7')","('法学院','8')","('经济学院','9')","('政治教育学院','10')","('旅游学院','11')","('资源与环境学院','12')","('计算机科学学院','13')","('体育系','14')","('信息科学系','15')");  
  var   Array7   =   new   Array("('请选择所在院系','0',true,true)","('无','1')");  
   
  function   load()  
  {  
  document.form1.School.options[0].selected=true;  
  document.form1.Dep.options[0].selected=true;  
  document.form1.Connect_tel.checked=false;  
  document.form1.Connect_bp.checked=false;  
  }  
   
  function   change_school(inForm,selected)  
  {  
  if   (document.form1.School.options.selectedIndex==7)  
  {  
  School_custom.style.display="";  
  Dep_custom.style.display="";  
  Dep_default.style.display="none";  
  }  
  else  
  {  
  School_custom.style.display="none";  
  Dep_custom.style.display="none";  
  Dep_default.style.display="";  
   
  var   selectedArray   =   eval("Array"   +   selected);  
  while   (selectedArray.length   <   inForm.Dep.options.length)  
  {  
  inForm.Dep.options[(inForm.Dep.options.length   -   1)]   =   null;  
  }  
  for   (var   i=0;   i   <   selectedArray.length;   i++)  
  {  
  eval("inForm.Dep.options[i]="   +   "new   Option"   +   selectedArray[i]);  
  }  
  }  
  }  
  function   add_conn()  
  {  
  if   (document.form1.Connect_tel.checked==true)  
  {  
  Tel_custom.style.display="";  
  }  
  else  
  {  
  Tel_custom.style.display="none";  
  }  
  if   (document.form1.Connect_bp.checked==true)  
  {  
  BP_custom.style.display="";  
  }  
  else  
  {  
  BP_custom.style.display="none";  
  }  
  }  
   
  function   checkchar(str)  
  {  
  var   temp=str.length;  
  for   (i=0;i<temp;i++)  
  {  
  if   ((str.charCodeAt(i)>57)   &&   (str.charCodeAt(i)<65))  
  {  
  return   false;  
  }  
  if   ((str.charCodeAt(i)>90)&&(str.charCodeAt(i)<97))  
  {  
  return   false;  
  }  
  if   (str.charCodeAt(i)<48)  
  {  
  return   false;  
  }  
  if   ((str.charCodeAt(i)>122))  
  {  
  return   false;  
  }  
  }  
  return   true;  
  }  
   
  function   checknum(str)  
  {  
  var   temp=str.length;  
  for   (i=0;i<temp;i++)  
  {  
  if   (str.charCodeAt(i)>57)  
  {  
  return   false;  
  }  
  if   (str.charCodeAt(i)<48)  
  {  
  return   false;  
  }  
  }  
  return   true;  
  }  
  function   emailcheck(email)  
  {    
  var   yufan   =   /^[_a-z0-9\-]+@([_a-z0-9]+\.)+[a-z0-9]{2,3}$/;    
  if(yufan.test(email))  
  {  
  return   true;  
  }  
  return   false;    
  }  
   
  function   check()  
  {  
  var   UserID=document.form1.UserID.value;  
  var   Passwd=document.form1.Password.value;        
  var   PasswordEnsure=document.form1.PasswordEnsure.value;  
  var   PassQue=document.form1.PassQue.value;  
  var   PassAns=document.form1.PassAns.value;  
  var   RealName=document.form1.RealName.value;  
  var   School=document.form1.School.value;  
  var   Dep=document.form1.Dep.value;  
  var   SchoolName_custom=document.form1.SchoolName_custom.value;  
  var   DepName_custom=document.form1.DepName_custom.value;  
  var   Connect_tel=document.form1.Connect_tel.checked;  
  var   Connect_bp=document.form1.Connect_bp.checked;  
  var   TeleNumber=document.form1.TeleNumber.value;  
  var   BPCall=document.form1.BPCall.value;  
  var   Address=document.form1.Address.value;  
  var   Email=document.form1.Email.value;  
   
  if   (UserID.length   ==   0)  
  {  
  alert("请您填写用户名");  
  document.form1.UserID.value="";  
  document.form1.UserID.select();  
  return   false;  
  }  
   
   
  if   (Passwd.length   ==   0)  
  {  
  alert("请您填写密码");  
  document.form1.Password.value="";  
  document.form1.Password.select();  
  return   false;  
  }  
   
  if   (!checkchar(Passwd))  
  {  
  alert("请您不要在密码中使用非法字符");  
  document.form1.Password.value="";  
  document.form1.Password.select();  
  return   false;  
  }  
   
  if   ((Passwd.length<"6")||(Passwd.length>"16"))  
  {  
  alert("请您填写位数在6-16位之间的密码");  
  document.form1.Password.value="";  
  document.form1.Password.select();  
  return   false;  
  }  
   
  if   (PasswordEnsure.length   ==   0)  
  {  
  alert("请您填写确认密码");  
  document.form1.PasswordEnsure.value="";  
  document.form1.PasswordEnsure.select();  
  return   false;  
  }  
   
  if   (!checkchar(PasswordEnsure))  
  {  
  alert("请您不要在确认密码中使用非法字符");  
  document.form1.PasswordEnsure.value="";  
  document.form1.PasswordEnsure.select();  
  return   false;  
  }  
   
  if   ((PasswordEnsure.length<"6")||(PasswordEnsure.length>"16"))  
  {  
  alert("请您填写位数在6-16位之间的确认密码");  
  document.form1.PasswordEnsure.value="";  
  document.form1.PasswordEnsure.select();  
  return   false;  
  }  
   
  if   (PasswordEnsure   !=   Passwd)  
  {  
  alert("您的密码和确认密码不相符   请您重新填写");  
  document.form1.PasswordEnsure.value="";  
  document.form1.Password.value="";  
  document.form1.Password.select();  
  return   false;  
  }  
   
  if   (PassQue.length   ==   0)  
  {  
  alert("请您填写密码提示问题");  
  document.form1.PassQue.value="";  
  document.form1.PassQue.select();  
  return   false;  
  }  
   
  if   (PassAns.length   ==   0)  
  {  
  alert("请您填写密码提示答案");  
  document.form1.PassAns.value="";  
  document.form1.PassAns.select();  
  return   false;  
  }  
   
  if   (RealName.length   ==   0)  
  {  
  alert("请您填写真实姓名");  
  document.form1.RealName.value="";  
  document.form1.RealName.select();  
  return   false;  
  }  
   
  if   (School   ==   0)  
  {  
  alert("请您选择您所在的学校");  
  document.form1.School.focus();  
  return   false;  
  }  
   
  if   (School   !=   7   &   Dep   ==   0)  
  {  
  alert("请您选择您所在的院系");  
  document.form1.Dep.focus();  
  return   false;  
  }  
   
  if   (School   ==   7   &   SchoolName_custom.length   ==   0)  
  {  
  alert("请您填写您所在的学校名称");  
  document.form1.SchoolName_custom.value="";  
  document.form1.SchoolName_custom.select();  
  return   false;  
  }  
   
  if   (School   ==   7   &   DepName_custom.length   ==   0)  
  {  
  alert("请您填写您所在的院系名称");  
  document.form1.DepName_custom.value="";  
  document.form1.DepName_custom.select();  
  return   false;  
  }  
   
  if   (Connect_tel   ==   false   &   Connect_bp   ==   false)  
  {  
  alert("请您至少选择一种联系方式");  
  document.form1.Connect_tel.focus();  
  return   false;  
  }  
   
  if   (Connect_tel   ==   true   &   TeleNumber.length   ==   0)  
  {  
  alert("请您填写您的电话号码");  
  document.form1.TeleNumber.value="";  
  document.form1.TeleNumber.select();  
  return   false;  
  }  
   
  if   (Connect_tel   ==   true   &   (!checknum(TeleNumber)))  
  {  
  alert("请您按照正确的格式填写您的电话号码");  
  document.form1.TeleNumber.value="";  
  document.form1.TeleNumber.select();  
  return   false;  
  }  
   
  if   (Connect_bp   ==   true   &   BPCall.length   ==   0)  
  {  
  alert("请您填写您的传呼号码");  
  document.form1.BPCall.value="";  
  document.form1.BPCall.select();  
  return   false;  
  }  
   
  if   (Connect_tel   ==   true   &   (!checknum(BPCall)))  
  {  
  alert("请您按照正确的格式填写您的传呼号码");  
  document.form1.BPCall.value="";  
  document.form1.BPCall.select();  
  return   false;  
  }  
   
  if   (Address.length   ==   0)  
  {  
  alert("请您填写详细通讯地址");  
  document.form1.Address.value="";  
  document.form1.Address.select();  
  return   false;  
  }  
   
  if   (Email.length   ==   0)  
  {  
  alert("请您填写邮件地址");  
  document.form1.Email.value="";  
  document.form1.Email.select();  
  return   false;  
  }  
   
  if   (!emailcheck(Email))  
  {  
  alert("请您填写合法的邮件地址");  
  document.form1.Email.value="";  
  document.form1.Email.select();  
  return   false;  
  }  
  return   true;  
  }  
   
  </script>  
  </head>  
   
  <body   bgcolor="#FFFFFF"   text="#000000"   leftmargin="5"   marginwidth="5"   topmargin="4"   marginheight="4"   onload="javascript:load()">    
  <center>  
      <script   src="../js/head0.js"></script>  
      <script   src="../js/logon.js"   language="JavaScript"></script>  
      <table   width="768"   border="0"   cellspacing="0"   cellpadding="0">  
          <tr>    
              <td   height="8"><img   src="../images/jt_small.gif"   width="1"   height="1"></td>  
          </tr>  
          <tr>    
              <td   valign="top"   align="center">    
                  <form   onsubmit="if(check()==false)return   false;"   name=form1   method=POST   action="reg_update_simple.php">  
                      <span   class="title">欢迎您加入<font   color="#FF6600">阶梯(jieti.net)</font>这个大家庭,您只需填写以下信息:</span><br>  
                      <br>  
                      说明:带(<font   color="#CA0000"><font   color="#CA0000">*</font></font>)的项为必填项。<br>  
                      <br>  
                      ------------------------------------------------------ <b>基本信息</b> ------------------------------------------------------  
      <br><br>  
                      <table   border=0   cellpadding=4   cellspacing=1   width=100%>  
                          <tr   bgcolor="E5F0F4">    
                              <td   width="25%"   height="2"   bgcolor="E5F0F4"   align="right">用户名:</td>  
                              <td   colspan="2"   width="75%"   height="2"   bgcolor="E5F0F4">    
                                  <input   name="UserID"   value=""   size=20   type=text   maxlength="18"   class="input1">  
                                  <font   color="#CA0000">*</font>   (   4-18位中文、字母或数字组合   )</td>  
  <tr>  
                          <tr   bgcolor="E5F0F4">    
                              <td   width="25%"   bgcolor="E5F0F4"   align="right">密码:</td>  
                              <td   colspan="2"   width="75%">    
                                  <input   name="Password"   value=""   size=20   type=password   maxlength="16"   class="input1">  
                                  <font   color="#CA0000">*</font>   (   6-16位字母或数字组合   )</td>  
                           
                          <tr   bgcolor="E5F0F4">    
                              <td   width="25%"   bgcolor="E5F0F4"   align="right">密码确认:</td>  
                              <td   colspan="2"   width="75%">    
                                  <input   name="PasswordEnsure"   value=""   size=20   type=password   maxlength=20   class="input1">  
                                  <font   color="#CA0000">*</font></td>  
                          <tr   bgcolor="E5F0F4">    
                              <td   width="25%"   bgcolor="E5F0F4"   align="right">密码提示问题:</td>  
                              <td   colspan="2"   width="75%">    
                                  <input   name="PassQue"   value=""   size=20   type=text   maxlength=20   class="input1">  
                                  <font   color="#CA0000">*</font>   </td>  
                          <tr   bgcolor="E5F0F4">    
                              <td   width="25%"   bgcolor="E5F0F4"   align="right"   >密码提示答案:</td>  
                              <td   colspan="2"   width="75%">    
                                  <input   name="PassAns"   value=""   size=20   type=text   maxlength=20   class="input1">  
                                  <font   color="#CA0000">*</font>   </td>  
                          <tr   bgcolor="E5F0F4">    
                              <td   width="25%"   bgcolor="E5F0F4"   align="right">性别:</td>  
                              <td   colspan="2"   width="75%">    
                                  <input   name="Sex"   type="radio"   value="0"   checked>  
                                  男    
                                  <input   name="Sex"   type="radio"   value="1"   >  
                                  女   <font   color="#CA0000">*</font>    
                          </tr>  
                          <tr   bgcolor="E5F0F4">    
                              <td   width="25%"   bgcolor="E5F0F4"   align="right">真实姓名:</td>  
                              <td   colspan="2"   width="75%">    
                                  <input   name="RealName"   value=""   size=20   type=text   maxlength=20   class="input1">  
                                  <font   color="#CA0000">*</font></td>  
                          </tr>  
                          <tr   bgcolor="E5F0F4">    
                              <td   width="25%"   bgcolor="E5F0F4"   align="right">所在学校:</td>  
                              <td   colspan="2"   width="75%">    
                                  <select   name="School"   onChange="javascript:change_school(document.form1,this.options[selectedIndex].value)">  
  <option   value="0">请选择所在学校</option>  
  <option   value=1>电子科技大学</option><option   value=2>四川大学</option><option   value=3>西南财经大学</option><option   value=4>成都理工大学</option><option   value=5>西南交通大学</option><option   value=6>四川师范大学</option><option   value=7>其它学校</option>                                 </select>  
  <font   color="#CA0000">*</font></td>  
                          </tr>  
  <tr   bgcolor="E5F0F4"   id="School_custom"   style="display:none">    
                              <td   width="25%"   bgcolor="E5F0F4"   align="right">学校名称:</td>  
                              <td   colspan="2"   width="75%">    
  <input   type="text"   name="SchoolName_custom"   size="25"   class="input1">   <font   color="#CA0000">*</font>   (   请填写贵校全称   )  
                              </td>  
                          </tr>  
                          <tr   bgcolor="E5F0F4"   id="Dep_default"   style="display:">    
                              <td   width="25%"   bgcolor="E5F0F4"   align="right">所在院系:</td>  
                              <td   colspan="2"   width="75%">    
                                  <select   name="Dep">  
                                      <option   selected>请选择所在院系</option>  
                                  </select>  
                                  <font   color="#CA0000">*</font></td>  
                          </tr>  
  <tr   bgcolor="E5F0F4"   id="Dep_custom"   style="display:none">    
                              <td   width="25%"   bgcolor="E5F0F4"   align="right">院系名称:</td>  
                              <td   colspan="2"   width="75%">    
  <input   type="text"   name="DepName_custom"   size="25"   class="input1">   <font   color="#CA0000">*</font>   (   请填写院系全称   )  
                              </td>  
                          </tr>  
                          <tr   bgcolor="E5F0F4">    
                              <td   width="25%"   bgcolor="E5F0F4"   align="right">联系方式:</td>  
                              <td   colspan="2"   width="75%">    
                                  <input   type="checkbox"   name="Connect_tel"   onclick="add_conn()">  
                                  电话  
  <input   type="checkbox"   name="Connect_bp"   onclick="add_conn()">  
                                  传呼  
                                  <font   color="#CA0000">*</font>   </td>  
                          </tr>  
  <tr   bgcolor="E5F0F4"   id="Tel_custom"   style="display:none">    
                              <td   width="25%"   bgcolor="E5F0F4"   align="right">电话号码:</td>  
                              <td   colspan="2"   width="75%">    
  <input   name="TeleNumber"   value=""   size=15   type=text   maxlength=20   class="input1">   <font   color="#CA0000">*</font>   (   请使用   0286622021   这样的格式填写   )  
                              </td>  
                          </tr>  
  <tr   bgcolor="E5F0F4"   id="BP_custom"   style="display:none">    
                              <td   width="25%"   bgcolor="E5F0F4"   align="right">传呼号码:</td>  
                              <td   colspan="2"   width="75%">    
  <input   name="BPCall"   value=""   size=15   type=text   maxlength=20   class="input1">   <font   color="#CA0000">*</font>   (   请使用   969917654321   这样的格式填写   )  
                              </td>  
                          </tr>  
                          <tr   bgcolor="E5F0F4">  
                              <td   width="25%"   bgcolor="E5F0F4"   align="right">所在宿舍:</td>  
                              <td   colspan="2"   width="75%">  
                                  <input   name="Address"   value=""   size=52   type=text   maxlength=50   class="input1">  
                                  <font   color="#CA0000">*</font>   (详细通讯地址)</td>  
                          </tr>  
                          <tr   bgcolor="E5F0F4">    
                              <td   width="25%"   bgcolor="E5F0F4"   align="right">邮件地址:</td>  
                              <td   colspan="2"   width="75%">    
                                  <input   name="Email"   value=""   size=30   type=text   maxlength=75   class="input1">  
                                  <font   color="#CA0000">*</font>   (请使用英文、阿拉伯字母以及下划线、连接线组成的邮件帐号)</td>  
                          </tr>  
                      </table>  
                      <br>  
                      <p>    
                          <input   type=submit   value="确 定"   name="submit"   class="input1">                              
                          <input   type=reset   value="重 设"   name="reset"   class="input1">  
                      </p>  
                  </form>  
              </td>  
          </tr>  
      </table>  
      <script   src="../js/copy.js"></script>  
  </center>  
  </body>  
  </html>  
  Top

2 楼zxyufan(宇凡)回复于 2001-11-20 21:18:46 得分 0

选择了学校,则自动产生对应的院系。Top

3 楼debussy(debussy)回复于 2001-11-22 08:08:03 得分 0

可是我的是在项目是在数据库中产生的阿,不是写到源代码中的,请问这样该怎么实现?Top

4 楼debussy(debussy)回复于 2001-11-26 21:59:59 得分 0

谢谢大家,我已经解决了,使用PHP就好了,以前真的很笨,其实很简单的,产生<select   >  
  然后<option>部分用PHP查出来一个一个填就好了,呵呵Top

5 楼zxyufan(宇凡)回复于 2001-11-27 00:01:17 得分 0

我最前面的那一大段JS的数组定义就是用的一个自己写的PHP的函数做出来的~~就是循环一下,echo几下嘛~~Top

6 楼debussy(debussy)回复于 2002-01-09 13:47:03 得分 0

嗯,分给你Top

相关问题

  • 下面是MYSQL数据库表单
  • 表单与数据库连接问题
  • 关于数据库的表单~~~~~~(在线)
  • 从表单接收数据,INSERT到数据库中 ......Holen
  • 在同一个表单中如何取数据库数据
  • 如何通过表单删除数据库数据?
  • 表单数据提交数据库的问题,请指教!
  • 如何提取InfoPath表单数据 到数据库
  • 表单有200个项目,必填的有10个,怎样写入数据库才不会出错啊?
  • 请问FRONTPAGE里的表单和数据库怎么相连

关键词

  • 密码
  • 字母
  • 院系
  • 填写
  • 所在
  • 使用

得分解答快速导航

  • 帖主:debussy
  • zxyufan

相关链接

  • Web开发类图书

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo