关于mysql_query()的问题
$sql=mysql_query("select*fromadminwherename='".$this->name."'andpwd='".$this->pwd."'"...
$sql=mysql_query("select * from admin where name='".$this->name."' and pwd='".$this->pwd."'");
$row=mysql_num_rows($sql);
echo "$row Rows\n";
关于这个语句,数据库已经连接好了,admin是其中的一个表,我已经在这个表中插入了值,name为admin,pwd为admin。但在我在登陆界面输入admin和admin并提交之后,网页显示的是0 Rows,这是怎么回事?
这是login.php里的全部代码:
<?php
mysql_connect("localhost","root","1991421");
mysql_select_db("library");
mysql_query("set names utf8");
session_start();
$A_name=$_POST[name];
$A_pwd=$_POST[pwd];
class check_input{
var $name;
var $pwd;
function check_input($a,$b){
$this->name=$a;
$this->pwd=$b;
}
function checkadmin(){
$sql=mysql_query("select * from admin where name='$this->name' and pwd='$this->pwd'");
$row=mysql_num_rows($sql);
echo "$row Rows\n";
echo "$this->name\n";
echo "$this->pwd\n";
if($row==0){
echo "<script language='javascript'>alert('用户名或密码错误!');history.back();</script>";
exit;
}
else{
echo "<script>alert('登录成功!');window.location='control_panel.php';</script>";
$_SESSION[admin_name]=$name1;
$_SESSION[pwd]=$pwd1;
}
}
}
$obj=new check_input(trim($name),trim($pwd));
$obj->checkadmin();
?> 展开
$row=mysql_num_rows($sql);
echo "$row Rows\n";
关于这个语句,数据库已经连接好了,admin是其中的一个表,我已经在这个表中插入了值,name为admin,pwd为admin。但在我在登陆界面输入admin和admin并提交之后,网页显示的是0 Rows,这是怎么回事?
这是login.php里的全部代码:
<?php
mysql_connect("localhost","root","1991421");
mysql_select_db("library");
mysql_query("set names utf8");
session_start();
$A_name=$_POST[name];
$A_pwd=$_POST[pwd];
class check_input{
var $name;
var $pwd;
function check_input($a,$b){
$this->name=$a;
$this->pwd=$b;
}
function checkadmin(){
$sql=mysql_query("select * from admin where name='$this->name' and pwd='$this->pwd'");
$row=mysql_num_rows($sql);
echo "$row Rows\n";
echo "$this->name\n";
echo "$this->pwd\n";
if($row==0){
echo "<script language='javascript'>alert('用户名或密码错误!');history.back();</script>";
exit;
}
else{
echo "<script>alert('登录成功!');window.location='control_panel.php';</script>";
$_SESSION[admin_name]=$name1;
$_SESSION[pwd]=$pwd1;
}
}
}
$obj=new check_input(trim($name),trim($pwd));
$obj->checkadmin();
?> 展开
2个回答
展开全部
$sql=mysql_query("select * from admin where name='$this->name' and pwd='$this->pwd'");
单引号内的变量~php可能不会去解析。。会被当做为一个字符串。。不防加个字符串链接吧。。
$sql=mysql_query("select * from admin where name='".$this->name."' and pwd='".$this->pwd."'");
单引号内的变量~php可能不会去解析。。会被当做为一个字符串。。不防加个字符串链接吧。。
$sql=mysql_query("select * from admin where name='".$this->name."' and pwd='".$this->pwd."'");
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询