2016-04-29 117 views
0

我已经创建了两个表名为登录和gotest.in gotest表我已经存储了用户的详细信息和独特的表中ID.in登录表我存储refid,用户名和password.refid是主键在gotest table中包含相同的ID值。当它通过URl时,我从一个表单获得ID。但当iam尝试登录时,它给我这个errpor“用户名或密码不正确!”。Php Mysql登录

这里是我的PHP代码我的登录页面

<?php 

include_once 'dbconnect.php'; 

    $renewid = $_GET['ID']; 



    $query = "SELECT refid, username, password FROM ipay_login WHERE refid = '$renewid'"; 

    $result = mysql_query($query) or die(mysql_error()); 

    while ($row = mysql_fetch_array($result)) { 

     $renewid = $row['refid']; 
     $uname = $row['username']; 
     $upass = $row['password']; 

     echo $renewid . '<br />'; 
     echo $uname . '<br />'; 
     echo $upass . '<br />'; 

    } 

if(isset($_POST['btn-signup'])) { 


    $uname = $_POST['username']; 
    $upass = $_POST['password']; 


    /*echo $uname,$upass,$renewid;*/ 

    $result1 = mysql_query("SELECT * FROM ipay_login WHERE username = '$uname' AND password = '$upass'"); 

    if(mysql_num_rows($result1) > 0) 
    { 
     echo "sucesss"; 
    } 
    else 
    { 
     echo 'The Username or password are incorrect!'; 
    } 


} 
?> 

<html> 
<head></head> 
<body> 
<form id="convertion" method="post"> 


<!--<input type="hidden" id="refid" name="refid" value="<?php /*$_GET['refid']; */?>" /><br/>--> 
<input type="text" id="username" name="username" /><br/> 
<input type="text" id="password" name="password" /><br/> 

<button type="submit" id="btn-signup" name="btn-signup">SUBMIT</button> 
</form> 
</body> 
</html> 

URL

http://xxx.yyy.example?ID=1000 
+0

如果用户名和密码都存储在'ipay_login'表中,那么为什么在SELECT查询中使用'gotest'表? –

+0

你为什么认为它应该输出不同的东西? –

+1

请注意,'mysql_ *'函数在PHP 5.5中被弃用,并且在PHP 7.0中被完全删除。使用['mysqli'](http://php.net/manual/en/book.mysqli.php)或['pdo'](http://php.net/manual/en/book.pdo.php)代替。 [这就是为什么你不应该使用'mysql_ *'函数](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)。 –

回答

1

尝试所有这一切都在..first登录更改REFID列ID.then运行下面的代码

<?php 

include_once 'dbconnect.php'; 


$renewid = $_GET['ID']; 

$query = "SELECT * FROM login WHERE ID = '$renewid'"; 

$result = mysql_query($query) or die(mysql_error()); 

while ($row = mysql_fetch_array($result)) { 


    $uname = $row['username']; 
    $upass = $row['password']; 

    echo $uname . '<br />'; 
    echo $upass . '<br />'; 

} 

if(isset($_POST['btn-signup'])) { 


    $uname = $_POST['username']; 
    $upass= $_POST['password']; 


    $result1 = mysql_query("SELECT * FROM login WHERE username = '$uname' AND password = '$upass'"); 

    if(mysql_num_rows($result1) > 0) 
    { 

     echo "sucess"; 

    } 
    else 
    { 
     echo 'The username or password are incorrect!'; 
    } 
} 
?> 

<html> 
<head></head> 
<body> 
<form id="convertion" method="post"> 

    <input type="text" id="username" name="username" /><br/> 
    <input type="text" id="password" name="password" /><br/> 

    <button type="submit" id="btn-signup" name="btn-signup">SUBMIT</button> 
</form> 
</body> 
</html>