Jump to content

Recommended Posts

<?php

$username='jose';

$password='javier';

 

$con = mysql_connect("localhost", "admin","");

 

mysql_select_db("usernames",$con);

 

if (!$con) {

  die('Not connected : ' . mysql_error());

             }

 

$report = mysql_query("SELECT * FROM usernames where username like '$username%' and password like '$password%'");// i been debating whether i should include %

 

while ($row = mysql_fetch_array($report))

{

       $correctusername = $row["username"];/* here since i ran the query in report it seems like i am being redundant bit but it make sense to clear the results with the report query before i read it, I dont know is my first username password code. */

       $correctpassword= $row ["password"];

       

        if($correctpassword==$password & $correctusername==$username)

       

        echo "The username and password has been verified.";

       

      }

/*Yes. i realized this code is a begginers level dont bash me or talk down to me. */

 

?>

I would do it something like this

 

$sql = "SELECT * FROM usernames WHERE username='".$username."' AND password='".$password."' LIMIT 1"; // Since only 1 user should be able to have that combination
$result = mysql_query($sql);

if ($result)
    {
        $row = mysql_fetch_array($result);
        $correct_user = $row['username'];
        $correct_pass = $row['password'];
        
           if($correct_pass == $password && $correct_user == $username)
               { 
                     echo "The username and password has been verified.";
               }
     }

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.