Straight to the point...:)
I have problem connect to database. when I click Login button, the code can't read the username in my database.
I have checked the codes but i think there are some mistakes, but i don't know where it will be. Please help me. Here with I attach my login form and connection form...
Please help me soon. Thanks...

Dani AI

Generated

Short summary and extra checks based on this thread: reported that the login form could not read the username; diagnosed the connection call as the immediate issue and that resolved the problem. If similar symptoms appear again, the following targeted checks and a modern login pattern will help avoid the same trap and make the code safer for later PHP versions.

  • Turn on error reporting while debugging so connection errors are visible (temporarily).
  • Verify the MySQL server is reachable with the same credentials from the command line or a DB client.
  • Confirm the database and table names match exactly (case matters on some systems) and that the DB user has SELECT rights.
  • Check the HTML form: ensure input name attributes match the keys used in the script and the form method (POST vs GET) is correct.
  • Ensure session_start() is called before using session variables and trim inputs (empty spaces often hide “missing” usernames).
  • Be aware of character-set mismatches: store/compare values using the same encoding (utf8mb4 recommended).

Prefer using PDO or MySQLi with prepared statements and PHP’s password hashing functions instead of the old mysql_* calls. A minimal PDO pattern looks like this:

try {
    $pdo = new PDO('mysql:host=localhost;dbname=sarana;charset=utf8mb4','appuser','secret');
    $stmt = $pdo->prepare('SELECT password FROM users WHERE username = ? LIMIT 1');
    $stmt->execute([$username]);
    $hash = $stmt->fetchColumn();
    if ($hash && password_verify($password, $hash)) {
        // authenticated
    } else {
        // reject
    }
} catch (PDOException $e) {
    error_log($e->getMessage());
}

Avoid using the database root account in application code; create a least-privilege user instead. For reference on prepared statements and password handling see the PHP manual: PDO prepared statements and password_hash()/password_verify().

Recommended Answers

All 2 Replies

original koneksi.php

$connected = mysql_connect('localhost', 'root');
if( !connected ) {
die ("Connect to MySQL Server failed");
}

$retval = mysql_select_db("sarana", $connected);

if (!retval) {
die ("Database doesn't connect");
}

A couple changes are needed in your koneksi.php:

$connected = mysql_connect('localhost', 'root', 'password');
if( !$connected ) {
	die ("Connect to MySQL Server failed");
		 }

$retval = mysql_select_db("sarana", $connected);

if (!$retval) {
	die ("Database doesn't connect");
	     }

Thanks a lot for yor kind reply. I am satisfied. Once again, thank you...:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.