每日总结

1.今天学习php与mysql的连接


$link=mysqli_connect("localhost","root","123456");
if(!$link)
{
echo '连接失败';
}
mysqli_select_db($link,"goodlist");

mysqli_set_charset($link,'UTF-8');

$sql="select * from User";

$result=mysqli_query($link,$sql);
//处理数据
if($result)
{
//fetch_row获取行的数据
//mysqli_detch_assoc获取对应键值,$attr['linenum']可获取数据
//获取字段数
//echo mysqli_num_fields($result),"<br/>";
//获取信息数
//echo mysqli_num_rows($result),"<br/>";
$g_having=false;
while($attr=mysqli_fetch_array($result))
{
if($attr[0]==$name)
{
$g_having=true;
if($attr[1]==$password)
{
$_SESSION["name"]=$name;
$_SESSION["type"]=$attr[2];
header("location:showgood.php");
}
else{
header("location:index.php?message=WrongPassword!");
}
}

}
if(!$g_having)
{
header("location:index.php?message=WrongUsername!");
}
}
//关闭数据库连接
mysqli_close($link);


}else{
header("location:index.php?message=CaptchaError!");
}
}


原文地址:https://www.cnblogs.com/chenghaixiang/p/14914250.html