Jump to content

Login don't work!


hellboy012

Recommended Posts

Here is the code:

<html>
<head>
<title>Login</title>
</head>
<body>
<form action="" method="post">
Nick: <br /> <input type="text" name="nick" /> <br />
Pass: <br /> <input type="password" name="pass" /> <br />
<input type="submit" name="uloguj_se" value="Login" />

<?
if(isset($_POST['uloguj_se'])){
include("connect.php");
$nick = $_POST['nick'];
$pass = $_POST['pass'];
$nickdva = mysql_query("SELECT * FROM klijenti WHERE nick='$nick'");
$passdva = mysql_query("SELECT * FROM klijenti WHERE password='$pass'");
if($nick==$nickdva && $pass==$passdva) {
echo "<center>Poz! </center>";
} else {
echo "<center>Netacan username/pw.</center>";
}
echo "</form>";
echo "</body>";
echo "</html>";
}
?>	

Link to comment
Share on other sites

if(isset($_POST['uloguj_se']))  <-  wont work, its just the button's name.

 

Wont work (you are check 2 different things):

$nickdva = mysql_query("SELECT * FROM klijenti WHERE nick='$nick'");

$passdva = mysql_query("SELECT * FROM klijenti WHERE password='$pass'");

 

should be:

$nickdva = mysql_query("SELECT * FROM klijenti WHERE nick='$nick' and password='$pass'");

 

the rest you could develop.

Link to comment
Share on other sites

if(isset($_POST['uloguj_se']))  <-  wont work, its just the button's name.

 

Using the button name there is fine, upon pressing the submit button it sets the buttons name as a key and its value as a value in the $_POST array, thus using this allows you to determine if your form has been submitted.

 

hellboy012, you can change your code to how phppaper suggested, with the single query. However checking a variable against a mysql_query() returned value will achieve nothing. mysql_query() returns a MySQL resource, which is totally useless for what you want. You'll need to take it a bit further and determine if there are any rows, with mysql_num_rows.

 

$query = mysql_query("SELECT * FROM klijenti WHERE nick='$nick' AND password='$pass'");
if(mysql_num_rows($query) == 0){
   echo '<center>Netacan username/pw.</center>';
}else{
   echo '<center>Poz! </center>';
}

 

Good luck.

Link to comment
Share on other sites

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.