Dear Sirs,

Can you please check this code and comment what should be the proper one.

<label for="username">Username:</label> <br />
<input id="username" type="text" value="ENTER USERNAME" onclick="this.value='';" name="username"/>
</p> <p>
<label for="password">Password:</label> <br />
<input id="password" type="password" value="ENTER YOUR PASSWORD" onclick="this.value='';" name="password" />

here is the link for this one...

Dani AI

Generated

Brief diagnosis and practical fixes. The client-side “click-to-clear” trick discussed above makes the form fragile but is unlikely to be the root cause of “always denied” — the processing script usually is. As noted, focus on what the PHP handler actually receives and how it checks the database. , and were right to question the onclick approach: replace that fragile JS with HTML5 placeholders and make sure your form field names match what the server expects.

A minimal, modern form pattern (use this as a drop-in replacement for the current inputs):

<form method="post" action="login.php">
  <label for="uid">Username</label>
  <input id="uid" name="user" type="text" placeholder="your username" required autocomplete="username">

  <label for="pwd">Password</label>
  <input id="pwd" name="pass" type="password" placeholder="your password" required autocomplete="current-password">

  <button type="submit">Log in</button>
</form>

Server-side checklist and a safe example approach (use PDO + password_verify, enable errors while debugging):

<?php
error_reporting(E_ALL); ini_set('display_errors',1);
session_start();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  $user = trim($_POST['user'] ?? '');
  $pass = $_POST['pass'] ?? '';
  var_dump($_POST); // debug only

  $pdo = new PDO('mysql:host=localhost;dbname=dbname','dbuser','dbpass',[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);
  $stmt = $pdo->prepare('SELECT id,password_hash FROM users WHERE username = ? LIMIT 1');
  $stmt->execute([$user]);
  $row = $stmt->fetch(PDO::FETCH_ASSOC);

  if ($row && password_verify($pass, $row['password_hash'])) {
    $_SESSION['user_id'] = $row['id'];
    header('Location: dashboard.php'); exit;
  }
  // generic error on failure
}
?>

Quick troubleshooting list: enable/display PHP errors; do a var_dump($_POST) to confirm form names and values; verify the DB query returns a row; check whether stored passwords are hashed and use password_verify; trim whitespace and normalize case if your usernames are case-insensitive; remove any default value on the password field (that can accidentally be submitted). Remove debug output once fixed and never store plain-text passwords.

Recommended Answers

All 4 Replies

Member Avatar for Member #949455

an you please check this code and comment what should be the proper one.

I'm not familiar with javascript being part of a form that is in PHP.

I guess there is something wrong with your onclick="this.value='';"?

Cannot Log-in Properly(always denied) HTML

It also means that your form is wrong that you can't get access to the database to confirm whether the user has access.

So what is it you want to be triggered when there is an onclick event?

Have you tried putting this in a form and linking that to an action script? I'm not very familiar with javascript but what should onclick="this.value='';" do? can you show that part of the code?

When the form loads the input boxes have 'ENTER USERNAME' and 'ENTER YOUR PASSWORD' in them as values. The onclick event is just clearing those values so when the user clicks on the input box it empties the box so the user can type their username and password. The issue probably lies within the PHP code that processes the input. Can you post your PHP code?

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.