colombo colombo - 7 months ago 33
SQL Question

Php Mysql login

i have created two tables named login and gotest.in gotest table i have stored user details and unique in that table is ID.in login table i am storing refid, username and password.refid is the primary key which contains same value of ID in gotest table.i am getting from ID from one form when it passed through the URl.but when iam trying to login it gives me this errpor " The Username or password are incorrect! ".

Here is my php code

<?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 of my login page

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

Answer

Try this ..first of all change your refid column in login to ID.then run following code

<?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>
Comments