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
https://forums.phpfreaks.com/topic/236161-login-dont-work/
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
https://forums.phpfreaks.com/topic/236161-login-dont-work/#findComment-1214225
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
https://forums.phpfreaks.com/topic/236161-login-dont-work/#findComment-1214380
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.