1、loginProcess.php将从表单login.php中获取的$username = $_POST['username'];进行验证时,要从数据库获取该用户名的密码。

$sql="select password from admin where name='$username'";

一定要注意,要$username要被 ' ' 包围才行!!

2、验证密码:一般在数据库中保存密码时都会被 md5加密,故在验证时也要对输入密码加密一下 md5(string)

if($row=mysql_fetch_assoc($res)){
    if($row['password']==md5($password)){
        header("Location:empMain.php?username=$username"); //跳转时把用户名带过去,默认以GET全局变量携带
        exit();
    }
}

3、页面跳转:可以将本php的某值传入到跳转的新页面中去。而且此值默认保存在$_GET['']中。

header("Location:empMain.php?username=$username");
//依据总共的页数$PageCount,循环打印超链接,让用户指定页数
//使用链接传递数据默认使用GET方式传递
for($i=1;$i<=$PageCount;$i++){
    echo "<a href='emList.php?pagenow=$i'>[$i]</a>&nbsp;";
}
//看看是否用户指定了$PageNow,若未指定,否则默认为1
if(!$PageNow=$_GET['pagenow']){
    $PageNow=$_GET['pagenow'];
}

4、php文件中添加超链接等html元素,echo ' '; 注意:单引号包围

echo '<a href="login.php">返回登录页面</a>';

5、Ctrl+Alt+↓ 复制当前行到下一行(复制增加) ;Ctrl+D: 删除当前行;

6、html里的table元素:

<table border="1" cellspacing=0>边框为1 边框宽度为0

<tr></tr>表示一行

<th></th>表示表头

<td></td>表示每个格子的元素

在php里输出html的table表格:

echo '<h2>管理用户</h2>';
echo '<table border=1 cellspacing=0 bordercolor="blue">';
echo '<th>id</th><th>name</th><th>email</th><th>grade</th>'.
     '<th>salary</th><th>删除用户</th><th>修改用户</th>';

//打印从数据库中获取的数据
$sql="select * from emp";
$res=mysql_query($sql,$conn) or die(mysql_error());
while($row=mysql_fetch_row($res)){
    echo "<tr><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td><td>$row[4]</td><td>$row[0]</td><td>$row[0]</td></tr>";
}

7、对数据库数据按“分页”显示:要有以下几个变量

$PageNow : 当前页 由用户给定

$PageCount : 总共有多少页,计算得:ceil($RowCount/$PageSize);

$RowCount : 总共有多少条记录,从数据库获取 select count(id) from table;

$PageSize : 每页显示几条记录

例如,指定当前页为$PageNow,则要从数据库读取对应的记录。使用 select * from table limit a,b 读取table表中从a+1开始的b个记录

8、在mysql语句中插入数学公式要单独放,如下的 ($PageNow-1)*$PageSize. 不可以直接放在“  ” 里面,那样得不到计算结果,只能得到一个字符串。

$sql="select * from emp limit ".($PageNow-1)*$PageSize.",$PageSize";

9、使用echo输出 文字夹变量 时,要注意变量无法识别的情况

//显示”当前XX页/总共XX页“
echo "当前{$PageNow}页/总共{$PageCount}页";

若为  echo "当前$PageNow页/总共$PageCount页";  则很有可能找不到$PageNow变量,它会误以为 “$PageNow页“ 是一个变量从而找不到值。

10、使用自增加来快速复制自身数据库

insert into table (name,email,address) select name,email,address from table;

使用between来快速删除数据库中的数据。要删除id从10到10000的数据

delete from table where id between 10 and 10000;

11、要在php中插入html代码:

添加   ?>  <html>...</html> <php?

posted on 2014-07-16 22:30  lanxian  阅读(580)  评论(0编辑  收藏  举报