php连接数据库成功,但是无法查询到表,为什么?急!!!!!!

baidu_37087638 2017-02-15 05:40:18
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
session_start();
$con = mysqli_connect('localhost', 'root', '', 'beauty') or die("error");//连接数据库
if($con){
echo "成功";
}
$name="";
$psd="";
if((isset($_POST['username']))&&(isset($_POST['password']))){
$name=$_POST["username"];
$psd=$_POST["password"];
if($name==""||$psd==""){
echo "<script>alert('请输入用户名或密码!');history.go(-1);</script>";
}

else{
$sql="select * from domuser where username=`$name` and password=`$psd` ";

$result = mysqli_query($con,$sql);
$num = mysql_num_rows($result);
if ($num) {
$row = mysqli_fetch_array($result); //将数据以索引方式储存在数组中
echo "<script>alert('登录成功!');window.location='index.html';</script>";
} else {
/*echo "<script>alert('用户名或密码不正确!');history.go(-1);</script>";*/
}
}
}
?>
...全文
612 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
傲雪星枫 2017-02-15
  • 打赏
  • 举报
回复
你只是连接成功,但没有选择数据库,所以执行查询出错 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <?php session_start(); $con = mysqli_connect('localhost', 'root', '', 'beauty') or die("error");//连接数据库 if($con){ echo "成功"; } // 选择数据库为 "test" mysqli_select_db($con,"test") $name=""; $psd=""; if((isset($_POST['username']))&&(isset($_POST['password']))){ $name=$_POST["username"]; $psd=$_POST["password"]; if($name==""||$psd==""){ echo "<script>alert('请输入用户名或密码!');history.go(-1);</script>"; } else{ $sql="select * from domuser where username=`$name` and password=`$psd` "; $result = mysqli_query($con,$sql); $num = mysql_num_rows($result); if ($num) { $row = mysqli_fetch_array($result); //将数据以索引方式储存在数组中 echo "<script>alert('登录成功!');window.location='index.html';</script>"; } else { /*echo "<script>alert('用户名或密码不正确!');history.go(-1);</script>";*/ } } } ?>
Son_of_a_bitch 2017-02-15
  • 打赏
  • 举报
回复
报的什么错啊
xuzuning 2017-02-15
  • 打赏
  • 举报
回复
你没有指定具体的库

21,893

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧