drll85318 2013-05-12 22:55 采纳率: 100%
浏览 18

表单,登录名和密码不起作用

I'm trying to create a form with login and password but I can not authenticate. I have checked the mysql query and is ok. I think that the problem comes from $stmt->num_rows(); it returns 0.

PHP WITH THE FORM

<?require('cabecera.php');?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Pujas</title>
        <script type="text/javascript" src="jquery-1.9.1.min.js"></script>  
    </head>
    <body>
            <div id='login'>
                <input type="text" name="txtUser" id="txtUser">
                <input type="text" name="txtPass" id="txtPass">
                <input type="button" name="butConectar" id="butConectar" value="Conectar">
            </div>
    </body>
  <? if ($_SESSION['cMensaje']!='') { ?>
  <script language="javascript">
     alert('<?=$_SESSION['cMensaje']?>');
  </script>
  <? unset($_SESSION['cMensaje']); ?>
  <? } ?>
  <script>
  $("#butConectar").click(function() {
        var txtUser = $("#txtUser").val();
        var txtPass = $("#txtPass").val();
        /*if((txtUser=='') || (txtPass=="")){
            alert('Hay campos sin rellenar.');
        }*/
         $.ajax({type: "POST",
                     url: "pr17Login.php",
                     data: "txtUser="+txtUser+"&txtPass="+txtPass,
                     success:function(data) {
                         alert(data);
                     }
        })  

 })

PHP TO CHECK LOGIN AND PASSWORD

<?require('pr17conecta.php');
  require('cabecera.php');
  ini_set('display_errors',1); error_reporting(E_ALL);

    $user=$_POST['txtUser'];
    $password=md5($_POST['txtPass']);
    //$query=mysql_query("
        // select * from tb_user where username='$u' and password='$p'
       // ");
        $cSQL="SELECT LOGIN,CLAVE FROM USUARIOS WHERE LOGIN=? AND CLAVE=?";
        $stmt=$oConni->prepare($cSQL) or die($oConni->error);
        $stmt->bind_param('si',$user,$password);
        $stmt->execute();                               
        $stmt->bind_result($LOGIN,$CLAVE);
        $stmt->fetch(); 
    $row = $stmt->num_rows();
    if ($row == 1){
        session_start();
        $_SESSION['txtUser']=$LOGIN;
        header("location: pr17Pujas.php");
    }else{
        //header("location: pr17Login.php");
            echo 'Usuario o contraseña inválidos.';
    }
?>

CABECERA.PHP

    <? @header('Content-Type:text/html; charset=utf-8');
   session_start();
   define('MAX_IDLE_TIME', 3);
   ?>
  • 写回答

1条回答 默认 最新

  • doukong6031 2013-05-12 23:03
    关注

    num_rows is a property, not a method, of the mysqli result.

    You need to retrieve it using $stmt->num_rows not $stmt->num_rows().

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么