Home > Backend Development > PHP Tutorial > php批改数据库数据

php批改数据库数据

WBOY
Release: 2016-06-13 12:13:13
Original
1152 people have browsed it

php修改数据库数据
先查询某条件数据,希望点击修改能够弹出另外一窗口,该窗口有所有表的字段(控件形式表现),在该窗口的控件中对当前数据进行修改。请问应该如何实现?

<br /><!DOCTYPE HTML><br /><html> <br /><body><br /><br /><form  method="POST"><br /><input type="reset" value="重置"><p><br />员工编号:<input type="text" value="<?php if(isset($_POST['name'])){echo $_POST['name'];}?>"  name="name"><br /><input type="submit" name="submit1" value="查询"><p><br />员工姓名:<input type="text"  value="<?php if(isset($_POST['name1'])){echo $_POST['name1'];}?>" name="name1"><br /><input type="submit" name="submit2" value="查询"><p><br /></form><br /></body><br /><?php<br /><br />   header("Content-type:text/html;charset=utf-8");<br />   $serverName = "192.168.1.110,12590"; //local表示为本地,如果你用IP就不用括号了,1433表示端口<br />				//比如$serverName = "127.0.0.1,1433"; <br />   $database = "ee";<br />   $uid = "sa";<br />   $pwd = "ee234";<br /><br />   try {<br />      $conn = new PDO( "sqlsrv:server=$serverName;Database = $database", $uid, $pwd); <br />   }<br /><br />   catch( PDOException $e ) {<br />      die( "Error connecting to SQL Server".$e ); <br />   }<br />echo '<table border="1" align="center width=90%">';<br />echo '<caption><h1>员工档案一览</h1></caption>';<br />echo '<tr bgcolor="#cccccc">';<br /><br />echo '<th>_Identify</th><th>部门体系</th><th>工作部门</th><th>办事处</th><th>岗位名称</th><th>职位职级</th><th>职位层级</th><th>职系</th><th>员工编号</th><th>员工姓名</th><th>删除</th><th>修改</th>';<br />echo "<br>";<br />echo "<p></p>";<br />echo "\n";<br /><br />   if(isset($_POST['submit1'])) { <br />   //SQL语句<br />      $bh= $_POST['name'];<br />   $stmt= $conn->query("select _Identify,部门体系,工作部门,办事处,岗位名称,职位职级,职位层级,职系,员工编号,员工姓名 from 员工档案表 where 员工编号='$bh'");<br />   while (list ($_Identify,$部门体系, $工作部门, $办事处, $岗位名称, $职位职级, $职位层级, $职系, $员工编号, $员工姓名) = $stmt->fetch(PDO::FETCH_NUM)){<br />	   echo "<center>";<br />	   echo '<tr>';<br />	   echo '<td>'.$_Identify.'</td>';<br />	   echo '<td>'.$部门体系.'</td>';<br />	   echo '<td>'.$工作部门.'</td>';<br />	   echo '<td>'.$办事处.'</td>';<br />	   echo '<td>'.$岗位名称.'</td>';<br />	   echo '<td>'.$职位职级.'</td>';<br />	   echo '<td>'.$职位层级.'</td>';<br />	   echo '<td>'.$职系.'</td>';<br />	   echo '<td>'.$员工编号.'</td>';<br />	   echo '<td>'.$员工姓名.'</td>';<br />	   echo '<td>'."<a href='del.php?id=$_Identify'>删除</a>".'</td>';<br />	   echo '<td>'."<a href='alter.php?id=$_Identify'>修改</a>".'</td>';<br />	   echo '</tr>';<br />   }<br />   echo '</table>';<br />   <br />   }<br />   elseif(isset($_POST['submit2'])){<br />   $xm= $_POST['name1'];<br />   $stmt= $conn->query("select _Identify,部门体系,工作部门,办事处,岗位名称,职位职级,职位层级,职系,员工编号,员工姓名 from 员工档案表 where 员工姓名 like'%".$xm."%'");<br />   while (list ($_Identify,$部门体系, $工作部门, $办事处, $岗位名称, $职位职级, $职位层级, $职系, $员工编号, $员工姓名) = $stmt->fetch(PDO::FETCH_NUM)){<br />	   echo "<center>";<br />	   echo '<tr>';<br />	   echo '<td>'.$_Identify.'</td>';<br />	   echo '<td>'.$部门体系.'</td>';<br />	   echo '<td>'.$工作部门.'</td>';<br />	   echo '<td>'.$办事处.'</td>';<br />	   echo '<td>'.$岗位名称.'</td>';<br />	   echo '<td>'.$职位职级.'</td>';<br />	   echo '<td>'.$职位层级.'</td>';<br />	   echo '<td>'.$职系.'</td>';<br />	   echo '<td>'.$员工编号.'</td>';<br />	   echo '<td>'.$员工姓名.'</td>';<br />	   echo '<td>'."<a href='del.php?id=$_Identify'>删除</a>".'</td>';<br />	   echo '<td>'."<a href='alter.php?id=$_Identify'>修改</a>".'</td>';<br />	   echo '</tr>';<br />   }<br />   echo '</table>';<br />   }<br />    else{<br />	   $stmt= $conn->query("select _Identify,部门体系,工作部门,办事处,岗位名称,职位职级,职位层级,职系,员工编号,员工姓名 from 员工档案表");<br />   while (list ($_Identify,$部门体系, $工作部门, $办事处, $岗位名称, $职位职级, $职位层级, $职系, $员工编号, $员工姓名) = $stmt->fetch(PDO::FETCH_NUM)){<br />	   echo "<center>";<br />	   echo '<tr>';<br />	   echo '<td>'.$_Identify.'</td>';<br />	   echo '<td>'.$部门体系.'</td>';<br />	   echo '<td>'.$工作部门.'</td>';<br />	   echo '<td>'.$办事处.'</td>';<br />	   echo '<td>'.$岗位名称.'</td>';<br />	   echo '<td>'.$职位职级.'</td>';<br />	   echo '<td>'.$职位层级.'</td>';<br />	   echo '<td>'.$职系.'</td>';<br />	   echo '<td>'.$员工编号.'</td>';<br />	   echo '<td>'.$员工姓名.'</td>';<br />       echo '<td>'."<a href='del.php?id=$_Identify'>删除</a>".'</td>';<br />	   echo '<td>'."<a href='alter.php?id=$_Identify'>修改</a>".'</td>';<br />	   echo '</tr>';<br />   }<br />   echo '</table>';<br />   }<br />?><br /></html><br />
Copy after login

------解决思路----------------------
查询和修改不能同时完成
再说你 修改 不已经产生新页面了吗?

------解决思路----------------------
点击修改这些用js 和 ajax 实现会好点。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template