说明:

在linux系统中,利用搭建的服务器,编写两个页面,一个添加信息,一个展现信息;

主要涉及到:php+mysql的操作;

数据添加页面:

<html>
<head>
<meta http-equiv='content-type' content='text/html'; charset='utf-8'>
<title> Test Engineer info table add</title>
</head>

<body>
<div align='center'>
<form action='adduser.php' method='post'>

<h3> Test Engineer_info Table</h3>
<table width='500' bgcolor='#ccffcc' style='border-color' border='1'>
<tr align=center><td>name</td><td><input type="text" name="tname"/></td></tr> 
<tr align=center><td>age</td><td><input type="text" name="tage"/></td></tr> 
<tr align=center><td>hobby</td><td><input type="text" name="thobby"/></td></tr> 
<tr align=center> <td>job</td><td><input type="text" name="tjob"/></td></tr> 
<tr align=center><td colspan='2'><input type="submit" value="add info"></td></tr> 
</table>
</form>
</div> 
</body>
</html>

数据操作:

<?php

 $mysql_server_name= 'localhost';
 $mysql_username='mysqlname';
 $mysql_password='mysqlpassword';
 $mysql_database='mysql-database';
 
 $tname=$_POST[tname];
 $tage=$_POST[tage];
 $thobby=$_POST[thobby];
 $tjob=$_POST[tjob];
 


 $link = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);
 mysql_query("set names'utf8'");
 
  if (!$link)
     die('could not connect:' .mysql_error());
  else {
        /*echo "LAMP is success!MySql is right!Mysql_database is right";*/
    
        mysql_select_db( $mysql_database,$link);
        if(!empty($tname)){
    $sql_insert="insert into clt_testerinfo values('$tname','$tage','$thobby','$tjob')";
    mysql_query($sql_insert);
    }
         
        $sql_select="select * from  clt_testerinfo";
        $result=mysql_query($sql_select,$link);
     echo "Test Enginner info Table";
     echo '</br>';
     echo "<table width='800' bgcolor='#ccffcc' style='border-color' border='1'>";
     echo "<tr><td>name</td>";
     echo "<td>age</td>";
     echo "<td>hobby</td>";
     echo "<td>job</td></tr>";
    
     while($row = mysql_fetch_array($result))
    {
     echo "<tr><td>";
     echo $row[tname];
     echo "</td><td>";
     echo $row[tage];
     echo "</td><td>";
     echo $row[thobby];
     echo "</td><td>";      
     echo $row[tjob];
     echo "</td></tr>";
    
    }  
     echo "</table>";
    
    }
  mysql_close($link);
?>

 

posted on 2015-10-08 11:39  laclt  阅读(222)  评论(0编辑  收藏  举报