我在注册页面时不用填email和mot de pass(密码)就可以直接登录,登录到别人的账户,而在其他页面登录时没有填email和mot de pass(密码),javascript会提示,为什么在这注册页面登录javascript没有作用?
以下是我的login代码 :
<?PHP
session_start();
include("conn.php");
//$email=trim($_REQUEST['email']); 
//$mot_de_pass=trim($_REQUEST['mot_de_pass']);     
if (isset($_POST['email'])){
    
    $right_enter='0';
    $sql="select * from `clientcompte` where email='$_POST[email]' and mot_de_pass='$_POST[mot_de_pass]'";
    $result=mysql_query($sql);

    if ($row=mysql_fetch_assoc($result)){

$_SESSION['email']=$row['email'];
$_SESSION['nom']=$row['nom'];
$_SESSION['prenom']=$row['prenom'];

        $right_enter='1';

    }
    else{
        echo "<script language='javascript'>alert('email ou mot de pass error!');history.back();</script>";
    }  

    if($right_enter){
$temps=60;
setcookie("pseudo",$_SESSION['prenom']." ".$_SESSION['nom'], time()+$temps);
    echo "<script language='javascript'>alert('login success!');location='modifercompte.php';</script>";

       exit;
    }}
?>
谢谢大家!

解决方案 »

  1.   

    提交表单的时候,肯定要有登录按钮的呀,你要先判断有没有点击登录按钮
    if(isset($_POST['login'])){
      再写你的那些代码
    }
      

  2.   


    <?PHP
    session_start();
    include("conn.php");
    //$email=trim($_REQUEST['email']);  
    //$mot_de_pass=trim($_REQUEST['mot_de_pass']);      
    if (!empty($_POST['email'])){
        
      $right_enter='0';
      $sql="select * from `clientcompte` where email='$_POST[email]' and mot_de_pass='$_POST[mot_de_pass]'";
      $result=mysql_query($sql);
      $row=mysql_fetch_assoc($result);
      if ( !empty($row) ){$_SESSION['email']=$row['email']; 
    $_SESSION['nom']=$row['nom'];
    $_SESSION['prenom']=$row['prenom'];   $right_enter='1';   }
      else{
      echo "<script language='javascript'>alert('email ou mot de pass error!');history.back();</script>";
      }     if($right_enter){
    $temps=60;
    setcookie("pseudo",$_SESSION['prenom']." ".$_SESSION['nom'], time()+$temps);
    echo "<script language='javascript'>alert('login success!');location='modifercompte.php';</script>";  exit;
      }}
    ?>
    修改了下你的代码 ,再试试,问题可能出在if ($row=mysql_fetch_assoc($result))这句上
      

  3.   

    $result=mysql_query($sql);
    这一句改为$result=mysql_query($sql,$conn);