0

I am unable to login even tho I provided correct username and password, this is error

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a9752689/public_html/zadatak/index.php on line 79 (I am not sure what this error means, since I don't want to show any rows, I don't see purpose of this code in line 79

$result = mysql_fetch_array($sql);

ERROR: Neispravno korisnicko ime! (this error means I inserted wrong username even tho I did not)

and this is code from page, I have created database and tables, I deleted login from this code

if you need to try by yourself here is link Click Here and user administrator and password webservisi

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login</title>
<style type="text/css">
<!--
#form1 table {
    background-color: #003333;
}
.style1 {
    font-family: "Times New Roman", Times, serif;
    font-size: 14px;
    font-style: normal;
    color: #FFFFFF;
}
.style2 {
    font-family: "Times New Roman", Times, serif;
    font-size: 18px;
    font-style: normal;
    color: #FFFFFF;
}
body {
    background-color: #FFFFFF;
}
-->
</style>
</head>

<body>
<form id="form1" name="form1" method="post" action="index.php">
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <table width="100%" height="308" align="center" bordercolor="#000000">
    <tr>
      <td colspan="2"><div align="center"><img src="Slike/Logo it.JPG" width="262" height="76" /></div></td>
    </tr>
    <tr>
      <td width="426">&nbsp;</td>
      <td width="422">&nbsp;</td>
    </tr>
    <tr>
      <td><div align="right" class="style1">
        <p class="style1"><span class="style1">Korisnicko ime</span>:</p>
      </div></td>
      <td><input type="text" name="username" id="username" /></td>
    </tr>
    <tr>
      <td><div align="right" class="style1">Lozinka: </div>        
      <label></label></td>
      <td><input type="password" name="password" id="password" /></td>
    </tr>
    <tr>
      <td colspan="2"><label>
        <label></label>
        <?php
  //Podaci o bazi podataka
    $hostname = "";
    $db_username = "";
    $db_password = "";
    $db_name = "";
  if (isset($_POST['login'])){
  //Provjera korisnika
  $username = $_POST['username'];
  $password = $_POST['password'];
  if (empty($username) || empty($password)){
die('<hr>ERROR: MORATE POPUNITI SVA POLJA. <a
href="index.php">LogIn</a>.<br>');

  }

  $con = mysql_connect($hostname,$db_username,$db_password);
    if (!$con)
    {
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db($db_name, $con);
    $sql = mysql_query("select password from students where username ='".$username."'");
    $result = mysql_fetch_array($sql);
    if(!$result)
    die ("ERROR: Neispravno korisnicko ime!");
    if ($password != $result['password']){
    die ("ERROR: Neispravna lozinka!");
    }
    session_start();
    $_SESSION['korisnik'] = $username;
    if ($username == "administrator"){
    header("Location: admin.php");
    }else{
    header("Location: user.php");
    }
mysql_close($con);
  }
  ?>
<div align="center">
        <input type="submit" name="login" id="login" value="Prijava" />
      </div>
      </label></td>
    </tr>
    <tr>
      <td colspan="2"><div align="center" class="style1">
        <p class="style2">Provjera predmeta koje student može da sluša </p>
      </div></td>
    </tr>
  </table>
  <p>&nbsp;</p>
  <p align="center">
    <label></label>
  </p>
  <p align="center">
    <label></label>
  </p>
</form>
</body>
</html>

I tried changing $sql = mysql_query("select password from students where username ='".$username."'");

students into Students, because in database table is called Students, but then I get different type of error

thanks in advance

Edited by filipgothic

1
Contributor
1
Reply
12
Views
3 Years
Discussion Span
Last Post by filipgothic
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.